I’ve looked this up in the manual and on several forum posts and still can’t get this to work. I know it’s silly…
My problem is: I can’t check the name.gameObject of a raycast hit.
if (Physics.Raycast (ray, out hit) && hit.transform.tag == "Cube")
{
Instantiate(touchPoof, new Vector3(hit.transform.position.x, hit.transform.position.y, hit.transform.position.z), Quaternion.identity);
this.gameObject.GetComponent<Score>().GiveCubePoints();
//above works. below does not
if (hit.collider.gameObject.name == "redCube")
{
audioSrc.clip = redClip;
audioSrc.Play();
}
if (hit.transform.name == "blueCube")
{
audioSrc.clip = blueClip;
audioSrc.Play();
}
I know this is not an Audio problem because I tried simply putting:
if (Physics.Raycast (ray, out hit) && hit.collider.gameObject.name == "redCube")
{
Instantiate(touchPoof, new Vector3(hit.transform.position.x, hit.transform.position.y, hit.transform.position.z), Quaternion.identity);
this.gameObject.GetComponent<Score>().GiveCubePoints();
This time it did not instantiate the touchPoof… I tried debugging but I can’t get the hit to give the name
if (Physics.Raycast (ray, out hit))
{
Debug.Log(hit.collider.gameObject.name);
Instantiate(touchPoof, new Vector3(hit.transform.position.x, hit.transform.position.y, hit.transform.position.z), Quaternion.identity);
this.gameObject.GetComponent<Score>().GiveCubePoints();