示例#1
0
    //Control what happens when a bullet hits a rock
    protected void OnTriggerEnter2D(Collider2D collision)
    {
        //When the bullet hits a big rock, save the position of the rock so we can spawn 2 medium ones, add 1 to the score, increase the vIndex number for the rock creation, and then destroy the bullet and the rock
        if (collision.gameObject.name == "Rock Big(Clone)")
        {
            GameObject.Find("GameManager").GetComponent <NC_GM>().mSpawnPosition = collision.gameObject.transform.position;
            NC_GM.SetScore(+1);
            NC_GM.CreateRock(+1);
            Destroy(collision.gameObject);
            Destroy(gameObject);
        }

        //When the bullet hits a medium rock, save the position of the rock so we can spawn 2 small ones, add 2 to the score, increase the vIndex number for the rock creation, and then destroy the bullet and the rock
        else if (collision.gameObject.name == "Rock Medium(Clone)")
        {
            GameObject.Find("GameManager").GetComponent <NC_GM>().mSpawnPosition = collision.gameObject.transform.position;
            NC_GM.SetScore(+2);
            NC_GM.CreateRock(+2);
            Destroy(collision.gameObject);
            Destroy(gameObject);
        }

        //When the bullet hits a small rock, add 3 to the score, destroy the bullet and the rock, and then send a message to the console saying the rock has been destroyed
        else if (collision.gameObject.name == "Rock Small(Clone)")
        {
            NC_GM.SetScore(+3);
            Destroy(collision.gameObject);
            Debug.LogFormat("Rock Destroyed");
            Destroy(gameObject);
        }
    }
示例#2
0
 //Creates the bullet if/when the spacebar is down, using the shown values
 void DoFiring()
 {
     if (Input.GetKeyDown(KeyCode.Space))
     {
         NC_GM.CreateBullet(GunPosition.position, transform.up * Mathf.Max(4.0f, mVelocity.magnitude));
     }
 }
示例#3
0
    IEnumerator Respawn()
    {
        //If the player still has lives left, then create a new player ship after 1 second
        if (GameObject.Find("GameManager").GetComponent <NC_Lives>().in_lives > 0)
        {
            yield return(new WaitForSeconds(1));

            NC_GM.CreatePlayerShip();
        }
    }
示例#4
0
    public static NC_GM sGM = null;     //The static reference to the Singleton, its null anyway, but good reminder

    //We want to be up and running right away, before other stuff starts
    void Awake()
    {
        if (sGM == null)
        {                                      //If we are doing this for the first time ONLY
            sGM = this;                        //Now the static variable is reference to our instance
            DontDestroyOnLoad(sGM.gameObject); //This means it survives a scene change
            InitialiseGame();
        }
        else if (sGM != this)
        {  //If we get called again and are not the same as before, kill duplicate
            Destroy(gameObject);
        }
    }