Пример #1
0
 // Start is called before the first frame update
 void Start()
 {
     onGround    = false;
     enemyObj    = GameObject.FindGameObjectWithTag("enemy");
     line        = GetComponent <LineRenderer>();
     heroAiState = HeroAiState.MOVEANDATTACK;
 }
Пример #2
0
    void Shoot()
    {
        RaycastHit hit;
        //敵に向かって射撃
        Vector3 dir = enemyObj.transform.position - shootPoint.position;
        var     ray = new Ray(shootPoint.position, dir);

        Debug.DrawRay(shootPoint.position, dir, Color.red);
        line.SetPosition(0, shootPoint.position);
        //射撃
        if (Physics.Raycast(ray, out hit))
        {
            if (hit.transform.gameObject.tag == "enemy")
            {
                enemyObj.GetComponent <enemyAI>().HP -= 500;
                GameObject bulletClone = Instantiate(bullet, shootPoint.position, shootPoint.rotation);
                bulletClone.transform.position = hit.point;
                line.enabled = true;
                //当たり位置と射撃位置の間に射線を引く
                line.SetPosition(1, hit.point);
                //弾痕
                // bulletClone.transform.parent = hit.collider.transform;
                Destroy(bulletClone, 1);
            }
            else
            {
                if (heroAiState != HeroAiState.MOVEANDATTACK)
                {
                    heroAiState = HeroAiState.MOVEANDATTACK;
                }
            }
        }
        //射線0.1秒後にを消す
        Invoke("lineReset", 0.2f);
        shootTime = reshootTime;
    }