D
D
Dmitry Korolev2016-03-22 18:45:36
C++ / C#
Dmitry Korolev, 2016-03-22 18:45:36

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;
        }
    }
}

please tell me what is wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
NoKoK, 2016-03-22
@adressmoeistranici

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

D
Dmitry Eremin, 2016-03-22
@EreminD

.Find(x => x.Contains("myText"))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question