Im having this weird Problem With the ScreenPointToRay:
/Users/Shared/Unity/071216 Mow Envi 01/Assets/PickupObject.cs(25,25): Error CS1061: Type UnityEngine.GameObject' does not contain a definition for ScreenPointToRay’ and no extension method ScreenPointToRay' of type UnityEngine.GameObject’ could be found. Are you missing an assembly reference? (CS1061) (Assembly-CSharp)
It seems like the componend does not exist?
Any suggestions?
using UnityEngine;
using System.Collections;
public class PickupObject : MonoBehaviour {
GameObject mainCamera;
bool carrying;
GameObject carriedObject;
public float distance;
// Use this for initialization
void Start () {
mainCamera = GameObject.FindWithTag("MainCamera");
}
// Update is called once per frame
void Update () {
if(carrying) {
carry(carriedObject);
} else {
pickup ();
}
}
void carry(GameObject o)
{
o.GetComponent<Rigidbody>().isKinematic = true;
o.transform.position = mainCamera.transform.position + mainCamera.transform.forward * distance;
}
void pickup ()
{
if(Input.GetKeyDown (KeyCode.E))
{
int x = Screen.width / 2;
int y = Screen.height / 2;
Ray ray = mainCamera.ScreenPointToRay(new Vector3(200.200));
RaycastHit hit;
if(Physics.Raycast(ray,out hit)) {
Pickupable p = hit.collider.GetComponent<Pickupable> ();
if(p != null) {
carrying = true;
carriedObject = p.gameObject;
}
}
}
}
}