Search Unity

How to code?

Discussion in 'Scripting' started by M2aProductions, Nov 25, 2014.

  1. M2aProductions

    M2aProductions

    Joined:
    Jul 23, 2013
    Posts:
    7
    Hello there, community. I have been playing around with Unity3D for about a year now, and I've recently gotten really good at it. But it's only Unity3D itself I'm good at. I have been working on a game for a while, and now I need to add some enemies. I got an enemy script from a guy, it looks like this :

    var target : Transform;
    var moveSpeed = 3;
    var rotationSpeed = 3;
    var myTransform : Transform;

    function Awake(){ myTransform = transform;
    }

    function Start(){ target = GameObject.FindWithTag("Player";).transform;
    }

    function Update () { var lookDir = target.position - myTransform.position; lookDir.y = 0; // zero the height difference myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(lookDir), rotationSpeed*Time.deltaTime); myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
    }


    So I create a .js file, and open it in Monodevelop. I'm then greeted with this :

    #pragmastrict

    functionStart () {

    }

    functionUpdate () {

    }

    I assume I should just replace this with the code I got and then save. But then, apparently there's an error. I tried everything. Does anyone know what I'm doing wrong?
     
  2. PrimeDQ

    PrimeDQ

    Joined:
    Oct 18, 2013
    Posts:
    9
    keep #pragma strict in your code, other than that i have no idea
     
  3. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,913
    Reading the error will help.
     
  4. lorenalexm

    lorenalexm

    Joined:
    Dec 14, 2012
    Posts:
    307
    If the code you posted is an exact copy and paste from the document that you have, the issue would be found within your start method - there is an unwanted semicolon in your GameObject looked call.
     
  5. M2aProductions

    M2aProductions

    Joined:
    Jul 23, 2013
    Posts:
    7
    I got it fixed.