im trying to make it so it follows the wave point until it ether hits the end or focus target and if at end of wp it focuses a object but i cant seem to change the state to shooting any idea?
i have already got the pursue to work but i cant get the shooting state to work.
public class enemychaseshooting : MonoBehaviour {
public Transform player;
public Transform head;
public Transform Plane;
public Transform shipTarget;
string state = "patrol";
public GameObject[] waypoints;
int currentWP = 0;
public float rotSpeed = 0.2f;
public float speed = 1.5f;
float accuracyWP = 2.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Vector3 direction = player.position - this.transform.position;
direction.y = 0;
if (state == "patrol" && waypoints.Length > 0)
{
if (Vector3.Distance(waypoints[currentWP].transform.position, transform.position) < accuracyWP)
{
currentWP++;
if (currentWP >= 7)
{
state = "shooting";
}
}
/// rotate towards waypoint
direction = waypoints[currentWP].transform.position - transform.position;
this.transform.rotation = Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(direction), rotSpeed * Time.deltaTime);
this.transform.Translate(0, 0, Time.deltaTime * speed);
}
if (Vector3.Distance(player.position, this.transform.position) < 10 || state == "pursuing")
{
state = "pursuing";
this.transform.rotation = Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(direction), rotSpeed * Time.deltaTime);
if (direction.magnitude > 5)
{
this.transform.Translate(0, 0, Time.deltaTime * speed);
}
}
else
{
state = "patrol";
}
**if ( state == " shooting")
{
if (shipTarget != null)
{
transform.LookAt(shipTarget);
}**
}
}
}