TornadoTwins Tutorial Problem

Hi

I have been following the TornadoTwins Tutorial and I have done exactly what they do and I get errors everytime.

Here is my script to make my character move and shoot fireballs:

var BulletPrefab = UnityEngine.Transform;

var speed = 3.0;

var rotateSpeed = 3.0;

function Update ()
{ 
    var controller : CharacterController=GetComponent(CharacterController);

    var forward = transform.TransformDirection(Vector3.forward);
    var curSpeed = speed * Input.GetAxis ("Vertical");

    controller.SimpleMove(forward * curSpeed);
    transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);

    if(Input.GetButtonDown("Jump"))
    {
        var Bullet = Instantiate (BulletPrefab, UnityEngine.GameObject.Find("Spawn"),
        UnityEngine.Transform.position.identity, UnityEngine.Vector3, UnityEngine.Quaternion.identity);
    }

}       

Here is the error I get

Assets/Scripts/Worm.js(15,47): BCE0020: An instance of type 'UnityEngine.Transform' is required to access non static member 'position'.

What should I do?

well, i also have a modified tornado twins movearound script, but it looks like you are trying to make it a C+ script with the "UnityEngine."

you don't have to do that since this is (or should be) a javascript.

sooo... here's an example of what that should look like:

var Bullet = Instantiate(BulletPrefab, gameObject.Find("Spawn").transform.position, 
    Quaternion.identity);

yeah, it looks like you were making a script hybrid, half java, half C+

so just use this example to fit your needs.

To further explain the error, position is an instance variable (it's a property, but Unity does not distinguish the difference in js) so you must have an instance of a Transform to access that variable.

You treated it like a class variable, meaning you can access without an instance of the object, hence, it outputted the "non-static member".

To solve the problem, you simply need to find an instance in the scene. Creating a new Transform programmatically unattached to a GameObject would be a bad idea. So, using various methods, you must find a transform, then you can say transform.position.

For example:

function Update () {
    if(Input.GetButtonDown("Jump"))
    {
        var Bullet : GameObject = Instantiate (BulletPrefab, GameObject.Find("Spawn").transform.position,  UnityEngine.Quaternion.identity);
    }
}

In javascript, Unity also includes `using UnityEngine;` automatically so you do not have to reference the namespace when you access the class.

I am unsure how familiar you are with class vs. instance methods and functions so I might recommend reading some tutorials on programming concepts if you are new.

Right I have a slight problem: I tried both of the above and I have tried and tried her is what my script looks like now.

var speed = 3.0;
var rotateSpeed = 3.0;

function Update (){   

    var controller : CharacterController = GetComponent(CharacterController);
    var forward = transform.TransformDirection(Vector3.forward);  
    var curSpeed = speed * Input.GetAxis ("Vertical");

    controller.SimpleMove(forward * curSpeed);    
    transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);    

    if(Input.GetButtonDown("Jump"))
    {        
         Instantiate (GameObject.Find("FireBall"),
            GameObject.Find("Spawn").transform.position, 
            Quaternion.identity);  

    }
}

Here are the errors I get

UnityException: You are not allowed to call this function when declaring a variable. Move it to the line after without a variable declaration. If you are using C# don't use this function in the constructor or field initializers, Instead move initialization to the Awake or Start function. Worm..ctor () (at Assets/Scripts/Worm.js:3)


NullReferenceException UnityEngine.Object.Internal_InstantiateSingle (UnityEngine.Object data, Vector3 pos, Quaternion rot) (at E:/BuildAgent/work/68355d6e5d19d587/Runtime/Export/Generated/BaseClass.cs:46) UnityEngine.Object.Instantiate (UnityEngine.Object original, Vector3 position, Quaternion rotation) (at E:/BuildAgent/work/68355d6e5d19d587/Runtime/Export/Generated/BaseClass.cs:57) Worm.Update () (at Assets/Scripts/Worm.js:14)

Here is the script. FireBall needs to be called:FireBall Your spawn point needs to be called:Spawn

var speed = 3.0; var rotateSpeed = 3.0; var FireBall: Transform;

function Update () { var controller : CharacterController=GetComponent(CharacterController);

var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");

controller.SimpleMove(forward * curSpeed);
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);

if(Input.GetButtonDown("Jump"))
{
 var Bullet = Instantiate(FireBall, gameObject.Find("Spawn").transform.position, 
Quaternion.identity);

}

} @script RequireComponent(CharacterController)