Example #1
0
 void Start()
 {
     base.Start();
     originSpeed     = speed;
     batStateMachine = new BatStateMachine(this);
     player          = GameObject.FindGameObjectWithTag("Player");
     startPos        = transform.position;
     rigi            = GetComponent <Rigidbody2D>();
 }
    private void Shoot()
    {
        if (Random.Range(0, 2).Equals(0))
        {
            GameManager.Instance.soundManager.Play("BatShoot1");
        }
        else
        {
            GameManager.Instance.soundManager.Play("BatShoot2");
        }
        // transform.LookAt(GameManager.Instance.player.transform.position);
        BatStateMachine stateMachine = GetComponent <BatStateMachine>();
        // stateMachine.navAgent.updateRotation = true;
        Vector3    randomPos = new Vector3(stateMachine.shootingPoint.position.x + UnityEngine.Random.Range(-radius, radius), stateMachine.shootingPoint.position.y + UnityEngine.Random.Range(-radius, radius), stateMachine.shootingPoint.position.z);
        GameObject bullet    = GameObject.Instantiate(stateMachine.bulletPrefab, randomPos, Quaternion.identity);

        bullet.GetComponent <Rigidbody>().AddForce(transform.forward * stateMachine.enemy.stats.ShootingRange, ForceMode.Impulse);
        stateMachine.enemy.conditions.isChasing = true;
        // stateMachine.navAgent.updateRotation = true;
    }