Inheritance: MonoBehaviour
Esempio n. 1
0
    IEnumerator SpawnWaves()
    {
        while (true)
        {
            for (int i = 0; i < this.hazardCount; ++i)
            {
                Vector3    spawnPosition = new Vector3(Random.Range(minX, maxX), 0.0f, initialZ);
                Quaternion spawnRotation = Quaternion.identity;

                // FYI: In the tutorial, they had the DestroyByContact script obtain to reference
                //      to the GameController via the Start(...) method.  This meant that the
                //      DestroyByContact script relied upon a singleton object.  So, wiring things
                //      via the GameController itself just seemed a lot cleaner to me.
                GameObject       prefab = this.asteroids[Random.Range(0, this.asteroids.Length)];
                GameObject       h      = Instantiate <GameObject> (prefab, spawnPosition, spawnRotation);
                DestroyByContact dbc    = h.GetComponent <DestroyByContact> ();
                dbc.gameController = this;


                yield return(new WaitForSeconds(Random.Range(this.minGenWait, this.maxGenWait)));
            }

            yield return(new WaitForSeconds(this.waveWait));
        }
    }
Esempio n. 2
0
    IEnumerator SpawnWaves()
    {
        yield return(new WaitForSeconds(startWait));

        while (true)
        {
            for (int i = 0; i < hazardCount; i++)
            {
                GameObject hazard        = hazards[Random.Range(0, hazards.Length)];
                Vector3    spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
                Quaternion spawnRotation = Quaternion.identity;
                Instantiate(hazard, spawnPosition, spawnRotation);
                yield return(new WaitForSeconds(spawnWait));
            }
            yield return(new WaitForSeconds(waveWait));

            if (gameOver)
            {
                restartText.text = "Press 'F' for Restart";
                restart          = true;
                break;
            }
            {
                GameObject destroyContactObject = GameObject.FindGameObjectWithTag("Player");
                if (destroyContactObject != null)
                {
                    destroyContact   = destroyContactObject.GetComponent <DestroyByContact>();
                    musicSource.clip = sound1;
                    musicSource.Play();
                }
            }
        }
    }
    private void OnTriggerEnter(Collider other)
    {
        // Find all the tanks in an area around the shell and damage them.
        if (other.tag == "Boundary")
        {
            return;
        }

        Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_AsteroidMask);

        foreach (var collider in colliders)
        {
            var targetRigidbody = collider.GetComponent <Rigidbody>();

            if (!targetRigidbody)
            {
                continue;
            }

            DestroyByContact destroyByContactScript = collider.GetComponent <DestroyByContact>();
            int scoreValue = destroyByContactScript.scoreValue;
            gameController.AddScore(scoreValue);
            Instantiate(destroyByContactScript.explosion, collider.transform.position, collider.transform.rotation);
            Destroy(collider.gameObject);
        }

        gameController.ShakeCamera();

        Destroy(gameObject);
    }
Esempio n. 4
0
    void OnMouseDown()
    {
        string GameMode = PlayerPrefs.GetString("GameMode");

        if (GameMode == "ChildMode")
        {
            DestroyByContact destroyByContact = gameObject.GetComponent <DestroyByContact> ();
            gameController.AddScore(destroyByContact.scoreValue);
            Destroy(gameObject);
        }
    }
Esempio n. 5
0
    void SpawnBoss()
    {
        Vector3    spawnPosition;
        Quaternion spawnRotation;

        spawnPosition          = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
        spawnRotation          = Quaternion.identity;
        currentBoss            = (GameObject)Instantiate(bossList[currentBossIndex], spawnPosition, spawnRotation);
        currentBossScript      = (DestroyByContact)currentBoss.GetComponent <DestroyByContact>();
        currentBossScript.life = bossLife;
    }
 public void RemoveHazard(string _hazard_id)
 {
     //根据id去更新PlayerController的信息
     if (!hazardsList.ContainsKey(_hazard_id))
     {
         Debug.Log("出现多个玩家都击中同一个物体的现象,这里忽略掉,因为并不需要判断是谁击中了 ");
         return;
     }
     DestroyByContact pc = hazardsList[_hazard_id];
     pc.BeDestroyed();
     hazardsList.Remove(_hazard_id);
 }
Esempio n. 7
0
    private void Start()
    {
        instace = this;
        GameObject gameControllerObject = GameObject.FindWithTag("GameController");

        if (gameControllerObject != null)
        {
            gameController = gameControllerObject.GetComponent <GameController>();
        }
        if (gameController == null)
        {
            Debug.Log("No se pudo encontrar 'GameController' script");
        }
    }
Esempio n. 8
0
    void OnTriggerEnter(Collider col)
    {
        Destroy(col.gameObject);
        DestroyByContact asteroid = col.gameObject.GetComponent <DestroyByContact>();

        if (asteroid)
        {
            scorekeeper.ScorePoints(-50);
        }
        EnemyMover enemy = col.GetComponent <EnemyMover>();

        if (enemy)
        {
            scorekeeper.ScorePoints(-100);
        }
    }
Esempio n. 9
0
 void OnTriggerExit(Collider other)
 {
     if (other.gameObject.tag == "Player")
     {
         other.gameObject.transform.position = Vector3.zero;
     }
     else
     {
         try {
             DestroyByContact oDBC = other.GetComponent <DestroyByContact> ();
             Debug.Log(oDBC.scoreValue / -3);
             GameController.AddScore(oDBC.scoreValue / -3);
         } catch (NullReferenceException nre) {
         } finally {
             Destroy(other.gameObject);
         }
     }
 }
Esempio n. 10
0
    void Start()
    {
        GameObject gameControllerObject = GameObject.FindWithTag("GameController");

        if (gameControllerObject != null)
        {
            gameController = gameControllerObject.GetComponent <GameController>();
        }
        if (gameController == null)
        {
            Debug.Log("Cannot find 'GameController' script");
        }

        destroybycontact = GetComponent <DestroyByContact>();
        allowRotate      = false;
        StartCoroutine(FireRockets());
        Instantiate(particle, transform.position, transform.rotation);
    }
Esempio n. 11
0
    private void Update()
    {
        Time.timeScale += (1f / slowDuration) * Time.unscaledDeltaTime;
        Time.timeScale  = Mathf.Clamp(Time.timeScale, 0, 1);
        if (Input.GetButton("Fire1") && Time.time > nextFire)
        {
            nextFire = Time.time + fireRate;
            Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
            audio.Play();
        }
        else if (Input.GetButton("Jump") && Time.time > nextFire)
        {
            nextFire = Time.time + fireRate;
            StartCoroutine(ShotEffect());
            laserLine.SetPosition(0, shotSpawn.position);

            RaycastHit hit;
            Vector3    forwardPosition = new Vector3(shotSpawn.position.x,
                                                     shotSpawn.position.y,
                                                     shotSpawn.position.z + weaponRange);
            if (Physics.Raycast(
                    shotSpawn.position, forwardPosition, out hit, weaponRange))
            {
                laserLine.SetPosition(1, hit.point);
                DestroyByContact dbc = hit.collider.GetComponent <DestroyByContact>();
                dbc.Damage(rayDamage);
            }
            else
            {
                laserLine.SetPosition(1, forwardPosition);
            }
        }
        if (Input.GetButton("Fire3") && Time.time > nextTimePause)
        {
            nextTimePause = Time.time + timeRate;
            BulletTime();
        }
    }
	IEnumerator SpawnWaves ()
	{
		yield return new WaitForSeconds (startWait);
		while (true)
		{
			for (int i = 0; i < hazardCount; i++)
			{
                totalHazrds++;
                int randIndex = random.Next(0, hazards.Length);
                GameObject hazard = hazards[randIndex];
                
                //GameObject hazard = hazards [Random.Range (0, hazards.Length)];
                var r = random.NextDouble();
                float randX = (float)(r * (-spawnValues.x - spawnValues.x) + spawnValues.x);
    
                Vector3 spawnPosition = new Vector3(randX, spawnValues.y, spawnValues.z);
                //Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
                Quaternion spawnRotation = Quaternion.identity;
                GameObject hazardObj = Instantiate(hazard, spawnPosition, spawnRotation);

                DestroyByContact hazardhandle = hazardObj.GetComponent<DestroyByContact>();
                hazardhandle.ID = "hazard" + totalHazrds.ToString();
                hazardsList.Add(hazardhandle.ID, hazardhandle);

                yield return new WaitForSeconds (spawnWait);
			}
			yield return new WaitForSeconds (waveWait);
			
			if (gameOver)
			{
				restartText.text = "Press 'R' to Exit";
				restart = true;
				break;
			}
		}
	}
Esempio n. 13
0
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.R))
        {
            //Application.LoadLevel(Application.loadedLevel);

            SceneManager.LoadScene(0);
        }


        if (morte != vida) //vida
        {
            morte = vida;  //vida
            StartCoroutine(tempo());
            //Instantiate(addPlayer, transform.position, transform.rotation);
        }
        if (morte <= 0)
        {
            DestroyByContact.Destroy(gameObject);
        }



        if (score > 500)
        {
            nivel = 2;
        }
        if (score > 1000)
        {
            nivel = 3;
        }
        if (score > 1100)
        {
            nivel = 4;
        }
    }
Esempio n. 14
0
 // Use this for initialization
 void Start()
 {
     levelStarted = false;
     theCore = GameObject.FindGameObjectWithTag ("Core");
     coreValues = theCore.GetComponent<DestroyByContact> ();
 }