Question by
evolhaart · Feb 21, 2016 at 11:06 PM ·
c#camerascripting problemscreentoworldpoint
ScreenToWorldPoint error (C#)
When I use this code I get an error saying :
Assets/Scripts/PlayerMovement.cs(39,30): error CS1061: Type
Camera' 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!
Comment
Answer by evolhaart · Feb 21, 2016 at 11:20 PM
I solved it, I had another script named Camera which in some way made problems.