Disabling the object you just touched with raycast?

When I click on the ruby it prints a message and adds 100 points to my daikon forge gui label in the game.
I just need to disable the ruby after those two steps. Any ideas? Thanks in advance :slight_smile:

using UnityEngine;
using System.Collections;

public class TouchScore : MonoBehaviour {
	//varibles
	
	private RaycastHit hit;
    private GUIManager guiManager;
    int score;
	void Update() 
{
           Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
       
		if(Input.GetMouseButtonDown(0))
		 {
		 print(Input.mousePosition);
		if (Physics.Raycast(ray, out hit, 1000))
		 {  
		
		if (hit.collider.CompareTag("Ruby"))
		 {		
		   print("Hit ruby");
		   ProcessTreasure(GameObject go);
		
		}			
      }
  }
	
}

	void Start() 
	{ 
		
		GameObject guiManagerGO = GameObject.Find("GUIManager");
		
		if(!guiManagerGO)
			Debug.LogError("No GUIManager found!", this);
		guiManager = guiManagerGO.GetComponent<GUIManager>();
	
	
	}


	public void ProcessTreasure(GameObject go)
	{
		score = score + 100;
		// Update the score
		guiManager.SetTreasureScoreTo(score.ToString());
	    go.SetActive(false);
	}






}

I’m not sure what the problem is, just that I don’t see where you’re getting the “go” that you’re passing.
So I’m guessing it should be something like this:

if (Physics.Raycast (ray, out hit, 1000))
{
	if (hit.collider.CompareTag("Ruby"))
	{
		print ("Hit ruby");
		ProcessTreasure (hit.transform.gameObject);
	}
}

SetActive should works well, but I don’t understand what do you do at line number 23?

ProcessTreasure(GameObject go);

UPD: Nextremity suppose right way, I think :wink:

I am use to using

OnTriggerEnter(Collider other)  
{
 other.gameObject.SetActive(false);
}

Not using the raycast collider. Trying to disable the ruby after i click on it. Not my camera.

Have you tried the code I’ve posted? That sends the game object of the ruby to the ProcessTreasure method.

When you use the Physics.Raycast (ray, out hit, 1000), it stores the hit information in the hit variable. This variable contains the transform of the object that you hit, in this case the ruby.

Thanks got it to work.