Beispiel #1
0
        public void Plant(Player player, PlantData data)
        {
            var go = Instantiate(data.Prefab);

            go.transform.position = _spawner.position;
            go.transform.rotation = _spawner.rotation;

            _destroyable.Destroy();
        }
 void OnCollisionEnter(Collision other)
 {
     if (all || other.collider.CompareTag(enemyTag))
     {
         Destroyable destroyer = other.collider.GetComponent <Destroyable>();
         if (destroyer)
         {
             destroyer.Destroy();
         }
     }
     if (destroySelf)
     {
         Destroy(this.gameObject);
     }
 }
Beispiel #3
0
    IEnumerator CheckForMissiles()
    {
        Collider[]  missiles = FindMissiles();
        Destroyable missile  = Intercept(missiles);

        yield return(new WaitForSeconds(1f));

        if (missile != null)
        {
            missile.Destroy();
            target = null;
        }

        StartCoroutine(CheckForMissiles());
    }
Beispiel #4
0
    // Update is called once per frame
    /// <summary>
    /// Fire a ray and upon hit will call the game objects destroyable script.
    /// </summary>
    void Update()
    {
        if (Input.GetMouseButtonDown(0) && Cursor.lockState == CursorLockMode.Locked)
        {
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                Destroyable destroy = hit.transform.gameObject.GetComponent <Destroyable>();

                if (destroy != null)
                {
                    destroy.Destroy(hit);
                }
            }
        }
    }
Beispiel #5
0
    //Когда сработал триггер
    private void OnTriggerEnter2D(Collider2D other)
    {
        //Временная переменная, чтобы запомнить, кто вошел
        Respawnable respawnable = null;

        Destroyable destroyable = null;

        //Запоминаем, кто вошел и, если он имеет скрипт Respawnable
        if (other.gameObject.TryGetComponent(out respawnable) != false)
        {
            //То вызываем его метод Respawn()
            respawnable.Respawn();
        }

        if (other.gameObject.TryGetComponent(out destroyable) != false)
        {
            destroyable.Destroy();
        }
    }