- Home /
error with learning script
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.
Answer by andytouch · Oct 01, 2012 at 03:01 PM
The 'Transform.position' part of the instantiation needs to have a lower case 't'.
Hi there. Please be patient if your question/reply doesn't show straight away.
As a new user, your posts and questions are held in a moderator que until it is approved and then it is displayed. When your karma rises, you'll be able to post questions, comments and answers without waiting for someone to approve it =]
Answer by jaskij · Oct 01, 2012 at 02:41 PM
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.
Your answer
Follow this Question
Related Questions
Where do I start with unity? 3 Answers
Removing dead bodies, big lag issue. 2 Answers
error Assets/jorge.js(7,1):: BCE0044: expecting }, found ". 1 Answer
NullReferenceException 3 Answers
New to Unity. Would like advice. 5 Answers