Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Enemy : MonoBehaviour
- {
- [SerializeField]
- private GameObject _explosionPre;
- [SerializeField]
- private GameObject[] _cities;
- [SerializeField]
- private float _enemySpeed=0.25f;
- // Start is called before the first frame update
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- FallToCity();
- }
- //falll diagonally to city gameobject
- public void FallToCity()
- {
- int randomCity = Random.Range(0, _cities.Length-1);
- Vector3 destinationPos = _cities[randomCity].transform.position;
- Vector3 currentPos = transform.position;
- Vector3 direction = destinationPos - currentPos;
- transform.Translate(direction*Time.deltaTime*_enemySpeed);
- }
- private void OnTriggerEnter(Collider other)
- {
- if (other.gameObject.tag == "City")
- {
- Destroy(other.gameObject);
- Instantiate(_explosionPre, transform.position, Quaternion.identity);
- Destroy(gameObject);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment