- Home /
script is not working Using raycast show PopUp on click
Hi I new to Unity C# Scripting
I am trying to destroy object and show popup using raycast hit on mouse click
i am able to detect object on raycast hit but unable to show popup and destroying object
Please help me on this C# script
i have two script
for player to detect object
to show popup and destroy object
Player Script... using UnityEngine; using System.Collections;
public class Select : MonoBehaviour { public RaycastHit hit; // Use this for initialization void Start () {
}
// Update is called once per frame
void Update () {
Ray ray = Camera.main.ScreenPointToRay (new Vector3 (Screen.width / 2, Screen.height / 2, 0));
if (Physics.Raycast (ray, out hit, 10)) {
if(Input.GetMouseButton(0)){
if(hit.collider.gameObject.GetComponent<Interact>()){
hit.collider.gameObject.GetComponent<Interact>().OnLookEnter();
}
}
}
}
}
2.Object Script using UnityEngine; using System.Collections;
public class Interact : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void OnLookEnter(){
GameObject.Find("First Person Controller").GetComponent<MouseLook>().enabled = false;
GameObject.Find("Main Camera").GetComponent<MouseLook>().enabled = false;
Time.timeScale = 0.0f;
GameSettings.counter++;
GameSettings.showExitPopup = false;
Destroy (GameObject.Find("iPhone"));
if(GameObject.Find("iPhonePopup")){
GameObject.Find("iPhonePopup").SetActive(true);
}
}
}
Please Help ....
Your answer
![](https://koobas.hobune.stream/wayback/20220613171316im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Problem wiht RaycastHit2D ! Changing hit's sprite 1 Answer
My raycast does not work as espected 2 Answers
Problem with Touch Screen Raycast or Array 0 Answers
GUI label on raycast? 0 Answers