Пример #1
0
 protected void OnDisable()
 {
     if (doneSpawning)
     {
         rigidbody.velocity = Vector3.zero;
         if (catParticlePool == null)
         {
             catParticlePool = TapGOPoolSingleton <CatParticle> .PoolInstance();
         }
         TapGameObject particle = catParticlePool.GetObject();
         if (particle)
         {
             particle.gameObject.SetActive(true);
             particle.GetComponent <CatParticle>().PlayAtLocation(transform.position);
         }
         else
         {
             Debug.LogError("Could not play particle system");
         }
         gameManager.IncScore(1);
         popSound.Play();
     }
     doneSpawning = false;
     base.OnDisable();
 }
Пример #2
0
 void Update()
 {
     if (Input.GetButtonDown("Fire1"))
     {
         RaycastHit hit;
         Ray        tapRay = Camera.main.ScreenPointToRay(Input.mousePosition);
         Vector3    tapPos = Vector3.zero;
         if (Physics.Raycast(tapRay, out hit))
         {
             //Debug.Log(hit.transform.tag);
             // make sure the the ray hit the ground, if not, then the tap doesn't count
             if (hit.transform.tag != "Ground")
             {
                 //make sure it has a renderer and that its not red already
                 TempRend = hit.transform.GetComponent <Renderer>();
                 if (TempRend != null && TempRend.material.color != Color.red)
                 {
                     hit.transform.GetComponent <RedColor>().SwitchColor();
                 }
                 return;
             }
             tapPos = hit.point;
             tapPos = new Vector3(tapPos.x, tapAreaHeight, tapPos.z);
             // check if our tap position is within the range of any currently active tap areas
             foreach (TapGameObject ta in activeTapAreaPool.activeObjectList)
             {
                 Vector3 difference = (ta.transform.position - tapPos);
                 difference = new Vector3(difference.x, 0, difference.z); // ignore the y axis!!
                 float magnitude = difference.magnitude;                  // account for the size of the enemy
                 if (magnitude < TapArea.radius)
                 {
                     //Debug.Log("Cannot add area, already area in place");
                     return;
                 }
             }
         }
         else
         {
             return;
         }
         // we are not in range of any tap areas
         // set a fresh tap area and make it appear on the place
         TapArea freshTapArea = tapAreaPool.GetObject().GetComponent <TapArea>();
         // set our tap area as active
         freshTapArea.enabled = true;
         if (!freshTapArea)
         {
             Debug.LogError("freshTapArea was null!");
             return;
         }
         freshTapArea.transform.position = tapPos;
         freshTapArea.gameObject.SetActive(true);
         tapAreaSound.Play();
     }
 }
Пример #3
0
    public void SpawnEnemy()
    {
        int   i     = (int)(Random.value * (spawnPoints.Count - 1));
        Enemy enemy = enemyPool.GetObject().GetComponent <Enemy>();

        if (!enemy)
        {
            Debug.LogError("enemy not found");
        }
        enemy.transform.position = spawnPoints[i].position;
        enemy.transform.rotation = spawnPoints[i].rotation;
        enemy.SetTarget(target);
        enemy.gameObject.SetActive(true);
    }