void Update() { if (Sys.getFlag() == 1) { if (Sys.getPosition() != null) { //敵の方向情報を取得して差分を計算 var Direction = Sys.getPosition() /*.position*/ - transform.position; //y軸固定 Direction.y = 0; //よくわからん Quaternion Rotation = Quaternion.LookRotation(Direction); // forwardの向きがおかしい場合補正をかける float LocalNum = Rotation.eulerAngles.y; if (ForwardNum == 1) { LocalNum = LocalNum - 90; // 補正実行 Rotation = Quaternion.Euler(new Vector3(Rotation.eulerAngles.x, LocalNum, Rotation.eulerAngles.z)); //そっちへ向く transform.rotation = Quaternion.Slerp(transform.rotation, Rotation, 2f * Time.deltaTime); } if (ForwardNum == 5) { // 補正実行 Rotation = Quaternion.Euler(new Vector3(-90, LocalNum, Rotation.eulerAngles.z)); //そっちへ向く transform.rotation = Quaternion.Slerp(transform.rotation, Rotation, 2f * Time.deltaTime); } } } }
void Update() { if (Sys.getPosition() != null) { //Ray ray = new Ray(transform.position, Sys.getPosition()/*.position*/ - transform.position); RaycastHit hit; Physics.Linecast(transform.position, Sys.getPosition(), out hit); // Rayがなんかにヒットしたら if (hit.transform == null || hit.transform.CompareTag("Enemy")) { if (Sys.getFlag() == 1) { //連射速度 shotInterval = shotInterval + Time.deltaTime * 1; if (shotInterval >= AttackSpeed) { shotInterval = 0; GameObject bullet = (GameObject)Instantiate(bulletPrefab, transform.position, Quaternion.Euler(transform.parent.eulerAngles.x, transform.parent.eulerAngles.y, 0)); Rigidbody bulletRb = bullet.GetComponent <Rigidbody>(); bulletRb.AddForce(transform.forward * shotSpeed); //射撃されてから2秒後に銃弾のオブジェクトを破壊する Destroy(bullet, 2.0f); if (LeftFlag == 1) { Audio.PlayOneShot(Audio.clip); } } } } } }
void Update() { if (Sys.getFlag() == 1) { if (Sys.getPosition() != null) { //敵の方向情報を取得して差分を計算 var Direction = Sys.getPosition2() /*.position*/ - transform.position; //よくわからん Quaternion Rotation = Quaternion.LookRotation(Direction); //最大俯角,仰角の処理 float Angle = 360 - Rotation.eulerAngles.x; if (Angle >= 180) { Angle = Angle - 360; } if (Angle < 0) { if (-Angle > MaxAngle) { Angle = -MaxAngle; } } else { if (Angle > MaxAngle) { Angle = MaxAngle; } } if (ForwardNum == 1) { transform.localRotation = Quaternion.Euler(0, 0, Angle); } if (ForwardNum == 5) { transform.localRotation = Quaternion.Euler(-Angle + 0.1f, 0, 0); } } } }