protected override void Shot() { GameObject bullet = Instantiate( BulletObject, transform.position, Quaternion.identity ); var bulletComp = bullet.GetComponent <Bullet>(); Vector3 vDir = new Vector3(0.0f, 0.0f, 1.0f); //ターゲットしている。 var target = m_lockOn.GetTarget(); if (target != null) { vDir = target.transform.position - transform.position; vDir.Normalize(); } Quaternion bulletRot = new Quaternion(); bulletRot.SetLookRotation(vDir); bullet.transform.rotation = bulletRot; bulletComp.SetDirection(vDir); currentInterval = ShotInterval; }
// Update is called once per frame void Update() { if (m_lockOn == null) { return; } if (m_lockOn.GetTarget() == null) { const float Distance = 140.0f; Vector3 targetPos = transform.position + transform.forward * Distance; Vector3 LineEndPos = transform.position + transform.forward * Distance * 0.8f; //ラインを引く。 raserPointer.SetPosition(0, transform.position); raserPointer.SetPosition(1, LineEndPos); raserPointer.startColor = IdleLineColor; raserPointer.endColor = IdleLineColor; //照準を表示する。 AIMTarget.transform.position = targetPos; AIMTarget.material.color = IdleColor; } else { Vector3 enemyPos = m_lockOn.GetTarget().transform.position; Vector3 LineDir = enemyPos - transform.position; //向き。 float Length = LineDir.magnitude; //距離。 LineDir.Normalize(); Vector3 LineEndPos = transform.position + LineDir * Length * 0.8f; //ラインを引く。 raserPointer.SetPosition(0, transform.position); raserPointer.SetPosition(1, LineEndPos); raserPointer.startColor = TargetLineColor; raserPointer.endColor = TargetLineColor; //照準を表示する。 AIMTarget.transform.position = enemyPos; AIMTarget.material.color = TargetColor; } }