I’ve got a book to learn Unity basics. After retyping an IA script, i see that it’s full of errors.
It’s supposed to be a script which sets the “joueurVu” variable to true when the First Person Controller is at 5 meters of the alien.
using UnityEngine;
using System.Collections;
public class IA : MonoBehaviour {
bool joueurVu = false;
public GameObject joueur;
// Use this for initialization
void Start () {
joueur = GameObject.Find("First Person Controller");
}
// Update is called once per frame
void Update () {
if (getDistance() < 5) {
joueurVu = true;
print ("Joueur Vu!");
}
}
return Vector3.Distance(joueur.transform.position Transform.position);
float getDistance(){
}
}
Here’s the others errors I got
It appears that the book is outdated to Unity 4, i’m at Unity 5 and the interface is quite different, but it’s in french and it is a lot more comfortable. What should I do?
it’s important that you post the complete error message - it includes line number/character position of the error which will help us spot the problem and help you faster.
in this case, it looks like you’ve missed a comma on line 23. when you’re copying tutorials, you need to be certain that you copy EVERYTHING
The return line should be inside of the getDistance. And if you want to return a float, you have to give inputs. But I don’t understand why you made a new return float that only uses Vector3.Distance which does the exact same thing as Vector3.Distance. Why not just use Vector3.Distance?
Fixed version:
// Update is called once per frame
void Update () {
if (Vector3.Distance(joueur.transform.position Transform.position) < 5) {
joueurVu = true;
print ("Joueur Vu!");
}
}
Delete the return and getDistance lines. They aren’t needed.
I took a code from an other source, but now I have a parsing error despite no accolade are missing.
I searched for missing accolades, semicolons or bad syntax for a while, and I discovered that parsing error might be because of conflicted files (in any case what does it exactly mean) but the parsing error is still there. Here’s my code:
using UnityEngine;
using System.Collections;
public class IA : MonoBehaviour {
bool joueurVu = false; //le joueur est-il repéré?
public GameObject joueur; //le joueur
// Use this for initialization
void Start () {
/*On recherche le joueur avec son nom et la fonction Find*/
joueur = GameObject.Find("First Person Controller");
}
// Update is called once per frame
void Update () {
// If the player has been sighted and isn't dead...
if(enemySight.personalLastSighting != lastPlayerSighting.resetPosition && playerHealth.health > 0f)
// ... chase.
Chasing();
}
}
void using UnityEngine.Chasing;
{
// Create a vector from the enemy to the last sighting of the player.
Vector3 sightingDeltaPos = enemySight.personalLastSighting - transform.position;
// If the the last personal sighting of the player is not close...
if(sightingDeltaPos.sqrMagnitude > 4f)
// ... set the destination for the NavMeshAgent to the last personal sighting of the player.
nav.destination = enemySight.personalLastSighting;
// Set the appropriate speed for the NavMeshAgent.
nav.speed = chaseSpeed;
// If near the last personal sighting...
if(nav.remainingDistance < nav.stoppingDistance)
{
// ... increment the timer.
chaseTimer += Time.deltaTime;
// If the timer exceeds the wait time...
if(chaseTimer >= chaseWaitTime)
{
// ... reset last global sighting, the last personal sighting and the timer.
lastPlayerSighting.position = lastPlayerSighting.resetPosition;
enemySight.personalLastSighting = lastPlayerSighting.resetPosition;
chaseTimer = 0f;
}
}
}
Also, sometimes when i pass my mouse on the void before using UnityEngine.Chasing;, it tells me that this is an unexpected void, and sometimes it doesnt