Script Errors

using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour {

// Use this for initialization
void Start () {

var speed : float = 6.0 ;
var jumpSpeed : float = 8.0 ;
var gravity : float = 20.0 ;

}

// Update is called once per frame
void Update () {

}

what im doing wrong ?

Your script seems to be a mix of unity-script (or javascript as it actually called) and C#. The compiler will compile it as one of them depending on the extension: *.cs for C# and *.js for javascript. The way these different languages handle variables is different, as a result, your code won’t compile. I don’t know what type of script you are using, but here is a solution (make sure you put it in a C# file):

using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour
{
    /* Moved this part out of the Start method,
     * as I assume it is supposed to be used throughout the entire class.
     * The "[SerializeField]" tag is used to display the variables in the inspector.
     */
    [SerializeField]
    private float speed = 6.0f;
    [SerializeField]
    private float jumpSpeed = 8.0f;
    [SerializeField]
    private float gravity = 20.0f;

    // Use this for initialization
    void Start () {}
   
    // Update is called once per frame
    void Update () {}
}

This code won’t do anything particular, as nowhere is specified that it will do something.

1 Like

yeah i was just try to do something and my example was javascript that i try to write in C# script :smile: thanks anyway :slight_smile: