alperc
alperc

Reputation: 383

Unity 4 Adding GameObject and Collider References

How can I add the game object from above (Roed Knap, Hand etc.) into the script given below (at the picture)? unity

This is an example project. I can't figure out to reference GameObject's and Colliders into a Script.

What I want to do is very simple.

Make a GameObject with a Collider, and trigger something when collision happens.

So What I have is basically a GameObject Cube that has a Collider sphere added and for this isTrigger is selected. I want this trigger when entering, modify the text. Can you help me with initializing, referencing and other stuffs necessary, see below code. This is the code I work with.

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour {

    GameObject Cube;
    GUIText Text;
    Collider collision;
    // Use this for initialization
    void Start () {
        collision = Cube.GetComponent<Collider> ();
        Text = GetComponent ("GuiText") as GUIText;
    }

    // Update is called once per frame
    void Update () {

    }

    void onTriggerEnter(){
        Text.text = "Won"
    }
}

Upvotes: 3

Views: 357

Answers (1)

Everts
Everts

Reputation: 10701

Unity uses C# syntax for all of MonoBehaviour and engine namings. That is, a method starts with cap letter:

void OnTriggerEnter(Collider col){}

Upvotes: 1

Related Questions