// Use this for initialization void Start() { int num = Random.Range(0, allPaths.Length); transform.position = allPaths[num].transform.position; MoveOnPath yourPath = GetComponent <MoveOnPath>(); //yourPath.PathName = allPaths[num].name; }
// strelba private void Fire(Transform enemyGameobject) { MoveOnPath HP = enemyGameobject.GetComponentInParent <MoveOnPath>(); GameObject BulletGO = (GameObject)Instantiate(bullet, firepoint.position, gameObject.transform.rotation); Shot shot = BulletGO.GetComponent <Shot>(); shot.tower = this.gameObject.GetComponent <Tower>(); if (shot != null) { shot.seek(target); } }
void Update() { if (target == null) { Destroy(gameObject); return; } MoveOnPath HP = target.GetComponent <MoveOnPath>(); Vector3 dir = target.position - transform.position; float distanceThisFrame = speed * Time.deltaTime; if (dir.magnitude <= distanceThisFrame) { HP.HP -= tower.damage; HitTarget(); return; } transform.Translate(dir.normalized * distanceThisFrame, Space.World); }