s.a.m
October 1, 2012, 2:13pm
1
been learning from books/video.
one of the examples has a firing script
var speed = 3.0;
var crateprefab:Transform;
function Update()
{
if(Input.GetButtonDown(“fire1”))
{
var crate = Instantiate(crateprefab,Transform.position,Quaternion.identity);
crate.Rigidbody.Addforce(Transform.forward *2000);
}
}
only problem ive got now is when i put it onto unity i get the message "Assets/shoot.js(15,36): BCE0020: An instance of type ‘UnityEngine.Transform’ is required to access non static member ‘position’
what does it mean,if i cant figure it out then my learning unity comes to a sudden halt.any help for a noob appreciated.
The ‘Transform.position’ part of the instantiation needs to have a lower case ‘t’.
jaskij
October 1, 2012, 2:41pm
3
Format your code (the button with ones and zeroes).
Transform is a class name, not an object of that class - and that is what you need. Consider code below.
var speed = 3.0;
var crateprefab:Transform;
function Update() { if(Input.GetButtonDown(“fire1”)) {
var crate = Instantiate(crateprefab,transform.position,Quaternion.identity);
crate.Rigidbody.Addforce(Transform.forward *2000); }
}
The difference here is that transform (notice the small first letter) is a specific transform, used for the object you attach the script to.