- Home /
Assets/Standard Assets (Mobile)/Scripts/SidescrollControl.js(33,18): BCE0020: An instance of type 'UnityEngine.Transform' is required to access non static member 'Find'.
**I have a problem saving my script this is the part of the error might help me?
error: "Assets/Standard Assets (Mobile)/Scripts/SidescrollControl.js(33,18): BCE0020: An instance of type 'UnityEngine.Transform' is required to access non static member 'Find'."
code:
@script RequireComponent( CharacterController )
// This script must be attached to a GameObject that has a CharacterController
var moveTouchPad : Joystick;
var jumpTouchPad : Joystick;
var forwardSpeed : float = 4;
var backwardSpeed : float = 4;
var jumpSpeed : float = 16;
var inAirMultiplier : float = 0.25; // Limiter for ground speed while jumping
private var thisTransform : Transform;
private var character : CharacterController;
private var velocity : Vector3; // Used for continuing momentum while in air
private var canJump = true;
private var player:GameObject;
function Start()
{
**player=Transform.Find("player").GameObject;**
// Cache component lookup at startup instead of doing this every frame
thisTransform = GetComponent( Transform );
character = GetComponent( CharacterController );
I'm not sure of the right solution. It depends on whether you are looking for any game object or an immediate child object, or any child object. You are getting this specific error because you are using the class rather than the instance. That is this line:
player = Transform.Find("player").GameObject;
should be:
player=transform.Find("player").GameObject;
Note the lower case 't'.
As @robertbu said, it depends on what it is you want to find. Can you give us some info about the gameObject you want to find, and the gameObject this script will be on? That way we can tell you with confidence which line you should be using. It will either be the above, or the line mentioned in my answer.
Answer by hellguzz · Mar 21, 2014 at 11:22 PM
Try
player=GameObject.Find("player");
Why the GameObject at the end? GameObject.Find() returns a GameObject anyway.
Answer by VioKyma · Mar 21, 2014 at 09:57 PM
If you are looking for a child object, then this will work, otherwise it will not.
If the script is on a completely seperate game object to the player, you could use:
player = GameObject.Find("player");
If it is directly on the player gameObject, you don't need that statement at all as a simple gameObject will do that.