- Home /
Question by
Luminatas · Dec 06, 2014 at 04:59 PM ·
rotationtransformquaternion
An object reference is required for the non-static field, method, or property
ERROR : (line 43)
Error CS0120: An object reference is required for the non-static field, method, or property 'UnityEngine.Transform.position.get' (CS0120) (Assembly-CSharp)
Code :
using UnityEngine; using System.Collections;
public class CharacterMove : MonoBehaviour {
public float speed;
private Vector3 position;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if(Input.GetMouseButton(0))
{
//where player clicked
locatePosition();
}
//Move player
moveToPosition();
}
void locatePosition()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast(ray, out hit, 1000))
{
position = new Vector3(hit.point.x, hit.point.y, hit.point.z);
Debug.Log(position);
}
}
void moveToPosition()
{
Quaternion newRotation = Quaternion.LookRotation(position=Transform.position, Vector3.forward);
newRotation.x = 0f;
newRotation.z = 0f;
transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime * 10);
}
}
Help please
Comment
Answer by tanoshimi · Dec 06, 2014 at 05:00 PM
Transform is the class. transform is the instance.
Quaternion newRotation = Quaternion.LookRotation(transform.position, Vector3.forward);
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Get slerp to work just as LookAt(,Vector3.right) does 1 Answer
Boids for 2D 0 Answers