- Home /
This question was
closed Nov 23, 2014 at 05:23 AM by
robertbu for the following reason:
Duplicate Question
Question by
Harryliu · Nov 23, 2014 at 05:23 AM ·
javascript
What is wrong with this script?
this a script that allows player to pick up battery. what is wrong with this function? there is an error says
Assets/My stuff/My scripts/BatteryPickup.js(28,38): BCE0020: An instance of type 'UnityEngine.Transform' is required to access non static member 'position'.
code:
function Update()
{
var hit : RaycastHit;
var fwd = transform.TransformDirection(Vector3.forward);
if(Physics.Raycast(Transform.position, fwd, hit, rayLength))
{
if(hit.collider.gameObject.tag == "Battery")
{
guiShow = true;
if(Input.GetKeyDown("e"))
{
torchScript.lightSource.light.intensity = 1.5;
Destroy(hit.collider.gameObject);
}
else
{
guiShow = false;
}
}
}
}
Comment
You want to use 'transform' with a lower case 't'. Upper case 'Transform' is the class. Lower case 'transform' is the transform on this game object.