Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Parsing Error, can't find out the problem

Discussion in 'Scripting' started by Bahston, Jun 7, 2016.

  1. Bahston

    Bahston

    Joined:
    Jun 7, 2016
    Posts:
    2
    Forgive me, as I am new to coding and the like, but I don't see anything wrong with this javascript

    using UnityEngine;
    using System.Collections;

    public class Enemy : MonoBehaviour {
    public float deathDistance = 0.5f;
    public float distanceAway;
    public Transform enemyObject;
    public Transform target;
    private NavMeshAgent navComponent;

    void Start()
    {
    target = GameObject.FindGameObjectWithTag("Player").transform;
    navComponent = this.gameObject.GetComponent<NavMeshAgent>();
    }

    void Update()
    {

    float dist = Vector3.Distance(target.position, transform.position);

    if(target)
    {
    navComponent.SetDestination(target.position);
    }

    else
    {
    if(target = null)
    {
    target = this.gameObject.GetComponent<Transform>();
    }
    else
    {
    target = GameObject.FindGameObjectWithTag("Player").transform;
    }
    }
    if (dist <= deathDistance) {
    S***HitsFan ();
    {
    function S***HitsFan(); {
    ApplicationLoadLevel("Start Menu")
    //KILL PLAYER

    }
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,139
    If (target = null) should be if(target == null)

    == is comparision, = is trying to assign a value.

    Also, you don't need to getcomponent<Transform>. Should just work with gameObject.transform. or. just transform, if you just want to get the transform of the object the script is attached to.
     
  3. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    That's not JavaScript, it's C#.

    Also please use code tags when posting code. And say what the error you're getting actually is.
     
    LeftyRighty likes this.
  4. cjdev

    cjdev

    Joined:
    Oct 30, 2012
    Posts:
    42
    Code (javascript):
    1.  
    2. if (dist <= deathDistance) {
    3. S***HitsFan ();
    4. {
    5. function S***HitsFan(); {
    6. ApplicationLoadLevel("Start Menu")
    7. //KILL PLAYER
    8.  
    This part looks like it was pasted in and is not only missing closing brackets but it looks like the wrong language.