UnityEngine.Component does not contain definition for ViewportPointToRay
I'm getting this issue when I run debug the code. Any reason for it?
Here's the code:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Raycast : MonoBehaviour { private GameObject brick = null; %|488016895_2|% %|1304944553_3|% void Start () { %|-2127151731_5|% } %|509193057_7|% Ray ray = camera.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0)); %|916917827_9|% if (Physics.Raycast(ray, out hit)) %|-283513318_11|% %|1032998217_12|% print("I'm looking at nothing!"); %|78262174_14|% if (brick.tag == "Prop") %|-1015824587_16|% if (Input.GetKeyDown ("e")) { //Gets key "E" %|-1159245837_18|% clone.transform.parent = character.transform; Destroy (GameObject.Find("Graphics")); } %|-230994197_22|% } } }
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Raycast : $$anonymous$$onoBehaviour {
private GameObject brick = null;
public Transform player;
public GameObject character;
void Start () {
brick = GameObject.Find("tran(Clone)");
}
void Update () {
Ray ray = camera.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0));
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
print("I'm looking at " + hit.transform.name);
else
print("I'm looking at nothing!");
if (hit.transform.name == "tran(Clone)") {
if (brick.tag == "Prop")
{
if (Input.Get$$anonymous$$eyDown ("e")) { //Gets key "E"
GameObject clone = (GameObject)Instantiate (brick, player.position, player.rotation);
clone.transform.parent = character.transform;
Destroy (GameObject.Find("Graphics"));
}
}
}
}
}
Your answer
Follow this Question
Related Questions
camera viewport from rect to triangle 0 Answers
How to disable objects that are outside viewport? 1 Answer
How to keep animation playing when animated object exits the viewport 0 Answers
How to Hide/Show 3d text according to player's position? 0 Answers
Problems using Camera.main.ScreenToViewportPoint(Input.mousePosition) as it gives the wrong position 0 Answers