Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Tornadotwins script problem

Discussion in 'Scripting' started by El Beno, Apr 6, 2011.

  1. El Beno

    El Beno

    Joined:
    Dec 29, 2010
    Posts:
    41
    var speed = 7.0;
    var rotateSpeed = 3.0;
    var Fireball:Transform;
    var iceball:Transform;
    private var dead = false;

    function OnControllerColliderHit(hit : ControllerColliderHit)
    {

    if(hit.gameObject.tag == "fallout")
    {
    dead = true;
    }
    }


    function Update ()
    {
    var controller : CharacterController = GetComponent(CharacterController);
    transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
    var forward = transform.TransformDirection(Vector3.forward);
    var curSpeed = speed * Input.GetAxis ("Vertical");
    controller.SimpleMove(forward * curSpeed);

    if(Input.GetButtonDown("Fire2"))
    {
    var bullit = Instantiate(Fireball, gameObject.Find("fireballspawn").transform.position,Quaternion.identity);
    bullit.rigidbody.AddForce(transform.forward * 2000);
    }
    if(Input.GetButtonDown("Fire1"))
    {
    var bullet = Instantiate(iceball, gameObject.Find("fireballspawn").transform.position,Quaternion.identity);
    bullet.rigidbody.AddForce(transform.forward * 2000);
    }
    }

    function LateUpdate()
    if (dead);
    {
    transform.position : Vector3(0, 4, 0)
    gameObject.Find("Main Camera").transform.position = Vector3(0, 4, -10);
    dead = false;
    }
    @script RequireComponent(CharacterController)




    The above is my script, and I am getting some errors which should not be there (I think):

    The true and false words are not changing colour.

    Assets/action_scripts/MoveAround.js(43, 17) BCE0044: expecting EOF, found `}`. This one is about the 2nd lowest line.

    Expecting `}`, found `gameObject`. This is about the 4th lowest line.

    Unexpected token `if`. This is about the 6th lowest line.

    I am using the Tornadotwins youtube tutorials, and my script is almost exactly the same as theirs. Any advice would be much appreciated.
     
  2. fireside

    fireside

    Joined:
    Feb 6, 2011
    Posts:
    203
    Generally that error means you are missing a }. It's probably needed before function LateUdate();
     
  3. Satoh

    Satoh

    Joined:
    Feb 17, 2011
    Posts:
    56
    You have if(dead) after the LateUpdate function, but before the brackets that compose its contents.

    EDIT:

    function LateUpdate()
    if (dead);
    {

    transform.position : Vector3(0, 4, 0)
    gameObject.Find("Main Camera").transform.position = Vector3(0, 4, -10);
    dead = false;
    }

    EDIT: also with your if(dead); formatted this way, it can't do anything. Put it inside the LateUpdate() function and remove the ; from it.
     
    Last edited: Apr 6, 2011
  4. El Beno

    El Beno

    Joined:
    Dec 29, 2010
    Posts:
    41
    Thanks a lot, working now