//-------------------------------- // 3 - Shooting from another script //-------------------------------- /// <summary> /// Create a new projectile if possible /// </summary> public void Attack(bool isEnemy) { if (CanAttack) { shootCooldown = shootingRate; // Create a new shot var shotTransform = Instantiate(Arrow) as Transform; // Assign position shotTransform.position = transform.position; // The is enemy property ShotScript shot = shotTransform.gameObject.GetComponent <ShotScript>(); if (shot != null) { shot.isEnemyShot = isEnemy; } // Make the weapon shot always towards it EnermyMove move = shotTransform.gameObject.GetComponent <EnermyMove>(); if (move != null) { move.direction = this.transform.right; // towards in 2D space is the right of the sprite } } }
private ShootPlayer shootPlayer; // call class ShootPlayer // Start is called before the first frame update void Start() { InvokeRepeating("UpdateTarget", 0f, 0.5f); enermyMove = GetComponent <EnermyMove>(); enermyMoveRandomly = GetComponent <EnermyMoveRandomly>(); shootPlayer = GetComponent <ShootPlayer>(); }