How do i switch to a different state to target a certain thing?
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?
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);
}**
}
}
}
You asked the same question here. Please don't duplicate questions. If you want to add information or phrase it in a different way, edit your original question.
Follow this Question
Related Questions
How do i randomize certain waypoints at the end of a path? 0 Answers
I'm going nuts for 2 days about NullReferenceException error please help! 1 Answer
How to resume waypoints after it has run into something and messed up? 0 Answers
Why the loop in waypoints in not working when set to true? 0 Answers