Search Unity

Help! Parsing Error!

Discussion in 'Scripting' started by Skynova, Apr 22, 2014.

  1. Skynova

    Skynova

    Joined:
    Mar 18, 2014
    Posts:
    12
    Hi,I just start my journey of learning Unity

    I want to make my plane shoot rockets

    I build a rocket prefab and test the script,everything is fine

    then I edit my plane's script to this

    using UnityEngine;
    using System.Collections;

    public class Player : MonoBehaviour {
    protected Transform m_transform;
    // Use this for initialization
    void Start () {

    m_transform = this.transform;
    }
    public float mspeed = 1;
    public Transform m_rocket;


    // Update is called once per frame
    void Update () {
    //Vertical Move
    float movev = 0;

    //Horizontal Move
    float moveh = 0;

    if (Input.GetKey (KeyCode.UpArrow)) {
    movev -= 6 * mspeed * Time.deltaTime;
    }
    if (Input.GetKey (KeyCode.DownArrow)) {
    movev += 6 * mspeed * Time.deltaTime;
    }
    if (Input.GetKey (KeyCode.LeftArrow)) {
    moveh += 6 * mspeed * Time.deltaTime;
    }
    if (Input.GetKey (KeyCode.RightArrow)) {
    moveh -= 6 * mspeed * Time.deltaTime;
    }

    this.m_transform.Translate (new Vector3 (moveh, 0, movev));


    float m_rocketRate = 0;

    m_rocket += Time.deltaTime;

    if ( m_rocketRate <= 0)
    {
    m_rocketRate = 0.1f;

    if (Input.GetKey (KeyCode.Space) || Input.GetMouseButton (0))
    {
    Instantiate ( m_rocket, m_transform.position, m_transform.rotation);
    }
    }
    }


    Everything was okay until I add this

    m_rocket += Time.deltaTime;

    if ( m_rocketRate <= 0)
    {
    m_rocketRate = 0.1f;

    the Unity console say that there is parsing error

    but I cant find anyone

    I've been stared at the screen for 30 minutes

    Need help!! plz

    Thanks
     
  2. Findo

    Findo

    Joined:
    Mar 11, 2014
    Posts:
    368
    aw, let a fresh pair of eyes look at it :D\


    if ( m_rocketRate <= 0) { // you forgot this bracket.
    {
     
  3. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
  4. Skynova

    Skynova

    Joined:
    Mar 18, 2014
    Posts:
    12
    thanks,but it's still not work

    add " { " behind if ( m_rocketRate <= 0) right?
     
  5. Skynova

    Skynova

    Joined:
    Mar 18, 2014
    Posts:
    12
    Excuse me,I'll remember it next time

    but where can I find the code tags?or how to use it?

    thank you
     
  6. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    My whole post is a link to a thread that explains how to use it. Sometimes the forum doesn't show it properly as a link, but click it and it will work.
     
  7. Skynova

    Skynova

    Joined:
    Mar 18, 2014
    Posts:
    12
    Got it,thanks~
     
  8. Findo

    Findo

    Joined:
    Mar 11, 2014
    Posts:
    368
    SkyNova, no, in front of it.