When I use this code I get an error saying :
Assets/Scripts/PlayerMovement.cs(39,30):
error CS1061: TypeCamera' does not contain a definition for
ScreenToWorldPoint’ and no extension
methodScreenToWorldPoint' of type
Camera’ could be found (are you
missing a using directive or an
assembly reference?)
Heres the code:
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour
{
public Camera camera;
private Vector3 pos;
private Quaternion targetRotation;
private float rotationSpeed;
void Start ()
{
rotationSpeed = 3;
}
void Update ()
{
FaceMouse ();
}
void FaceMouse ()
{
pos = Input.mousePosition;
pos.z = 10;
pos = camera.ScreenToWorldPoint (pos);
targetRotation = Quaternion.LookRotation (pos - transform.position);
targetRotation.x = 0.0f;
targetRotation.z = 0.0f;
if (Vector3.Distance (pos, transform.position) > 1 && MouseMoved ()) {
transform.rotation = Quaternion.Slerp (transform.rotation, targetRotation, Time.deltaTime * rotationSpeed);
}
}
What am I doing wrong? Thanks in advance!