Answer the question
In order to leave comments, you need to log in
How to use Find correctly?
I tried to use find, but it refused to work.
I wrote it like this:
using UnityEngine;
using System.Collections;
public class BulletSound : MonoBehaviour {
private GameObject bullet;
private GameObject z;
void Start()
{
bullet = (GameObject)this.gameObject;
z = GameObject.Find("/Задания/PlaySoundPlayer");
}
void OnColliderEnter(Collision bullet)
{
if (bullet.CompareTag("Enemy"))
{
z.GetComponent<PlaySound2>().a2 = true;
}
if (bullet.CompareTag("Ring"))
{
z.GetComponent<PlaySound2>().a3 = true;
}
if (bullet.CompareTag("Plastic"))
{
z.GetComponent<PlaySound2>().a4 = true;
}
}
}
Answer the question
In order to leave comments, you need to log in
hand = GameObject.Find("Hand"); - search for a GameObject by name
respawns = GameObject.FindGameObjectsWithTag("Respawn"); - search for GameObject by tag
texture = (GUITexture) FindObjectOfType(typeof(GUITexture)); - search by type
if you need to find a GameObject with an AudioSource component and use value, this development option is possible:
we are looking for an object: GameObject sours = GameObject.Find("the name of the GameObject we are looking for");
look for source in it: sours.GetComponent().value = your value
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question