Welcome!

Welcome to our community forums, full of great people, ideas and excitement. Please register if you would like to take part.

This is extra text with a test link..

Register Now

Announcement

Collapse
No announcement yet.

Score problems on Skeet Shooter

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Score problems on Skeet Shooter

    I'm having trouble with the score system on the skeet shooter game. My problem is that I don't know how to make each pigeon have a different score. I accomplished this on the tin cup game by tagging each row with separate tags and calling a different ChangeScore function when the target was hit. For example the first row was 20 pts, the second was 40, and the third 60. Seeing as all the enemies on the skeet shooter are all marked as Pigeon how would I make each pigeon pass a different score? I want the chicken, condor, and dragon to be 20, 40, and 100 points. I also typed in the code from the whiteboard and I'm getting an error on the PigeonHealth pointValue part. Unity says "the name pointValue does not exist in the current context."

    Click image for larger version

Name:	script.jpg
Views:	1
Size:	208.7 KB
ID:	333687


    Pigeon Health code
    Code:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class PigeonHealth : MonoBehaviour
    {
        public int health = 100;
    
        public void DoDamage(int sentDamage)
        {
            health = health - sentDamage;
    
            if(health <= 0)
            {
                GameObject.Find("ScriptHolder").GetComponent<GameManager>().ChangeScore(pointValue);
                Destroy(gameObject);
            }
        }
    }
    ChangeScore portion of GameManager
    Code:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    using UnityEngine.SceneManagement;
    
    //using System;
    
    
    public class GameManager : MonoBehaviour
    {
        public Camera fpsCam;
        public int score;
        public Text scoreValue;
        public int highScore;
        public Text highScoreValue;
    
        [Header("General Stuff")]
        public string activeWeapon;
    
        [Header("Target Launcher")]
        public GameObject launcherBase;
        public GameObject launcher;
        public int remainingPigeons = 10;
        public Rigidbody[] pigeons;          //creates array of pigeons
        public float pigeonSpeed = 10f;
    
        [Header("Pistol")]
        public GameObject pistolPivot;
        int activeChamber = 1;
        public bool canFirePistol;
        public Image shell01;
        public Image shell02;
        public Image shell03;
        public Image shell04;
        public Image shell05;
        public Image shell06;
    
    
    
        [Header("Rocket")]
        public GameObject rocketPivot;
        public Rigidbody rocket;
        public float rocketSpeed = 20f;
        public GameObject launchPoint;
        public Image rocketIndicator;
        public bool canFireRocket;
    
    
        [Header("PSM")]
        public GameObject psmPivot;
        public GameObject launchPointPSM;
        public Rigidbody psmRocket;
        public float psmRocketSpeed = 10f;
        public GameObject psm;
        public bool canFirePSM;
        public Image psmIndicator;
    
    
        public void ChangeScore(int sentScore)
        {
            score = score + sentScore;
            scoreValue.text = score.ToString();
            if(score > highScore)
            {
                highScore = score;
                highScoreValue.GetComponent<Text>().text = highScore.ToString();
            }
        }

  • #2
    So you should have already had a pigeonHealth script that stored the pigeon's health and speed (that's how you should have made each pigeon fly at a different speed).

    So you current PigeonHealth script can just be adjusted to hold this score value:
    Code:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class PigeonHealth : MonoBehaviour
    {
        public int health = 100;
        public int myPointValue;
        public int speed;
    
        public void DoDamage(int sentDamage)
        {
            health = health - sentDamage;
    
            if(health <= 0)
            {
                GameObject.Find("ScriptHolder").GetComponent<GameManager>().ChangeScore(myPointValue);
                Destroy(gameObject);
            }
        }
    }
    And then for each prefab, you change the score so that the faster pigeons have the higher score.

    Comment


    • #3
      I currently have everything working correctly. The only thing left is to add sound to each enemy, but I'm confused as to how to make that happen. In the zombie game I had things separated by tags and used PlayOneShot.

      Comment


      • #4
        Lots of ways to do that. One simple way would be to create three game objects in your scene and assign a sound source to each. Then in your healthScript, when health<=0, go out and fire the specific sound you want (on the one GameObject that has the sound you want to fire).

        Comment

        Working...
        X