whenever i attach my script to the enemy it says to fix the script errors first. but i dont understand WHAT are the errors. Please help.
My script file:
using UnityEngine;
using System.Collections;
public class Patrol : MonoBehaviour {
public Transform[ ] patrolPoints;
public float moveSpeed;
private int currentPoint;
// Use this for initialization
void Start () {
transform.position = patrolPoints[0].position;
currentPoint = 0;
}
// Update is called once per frame
void Update () {
if(currentPoint >= patrolPoints.Length)
{
currentPoint++
}
transform.position = Vector3 MoveTowards(transform.position, patrolPoints[currentPoint].position, moveSpeed * Time.deltaTime);
}
}
Thanks for your help (not part from the script
)
What does the Unity Console say? You must solve all errors it’s showing, that’s not specifically linked to your scripts, that also might be caused by another script… so you first have to fix all those errors, after that you’re able to use the Unity Editor to drag&drop scripts on objects or change the attributes of them…
I dont know how to fix the errors… i dont know what is the error actually… whenever i close it says “fixing scripts” for something like a millesecond and then i try to attach it and again it isnt working!
Use this exactly
using UnityEngine;
public class Patrol : MonoBehaviour
{
public Transform[] patrolPoints;
public float moveSpeed;
private int currentPoint;
// Use this for initialization
void Start()
{
transform.position = patrolPoints[0].position;
currentPoint = 0;
}
// Update is called once per frame
void Update()
{
if (currentPoint >= patrolPoints.Length)
{
currentPoint++;
}
transform.position = Vector3.MoveTowards(transform.position, patrolPoints[currentPoint].position, moveSpeed * Time.deltaTime);
}
}
basically you forgot a semicolon after currentPoint++ also you forgot a period after Vector3 to call MoveTowards