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