I have a cube that the player can pick up and carry around (Cube A) and a static holder (Cube B) which the cube can be dropped into. If I wanted to trigger a simple message when Cube A is dropped on Cube B on screen how could I do this?
If you tag Cube A then you can use it in this function to determine if it has touched Cube B.
Make sure Cube A is set to trigger and place a script like this on Cube B.
The sample code i put there is c#, sorry i should of said, I’m not sure how the trigger functions differ from javascript. Post the whole script for the Cube on and ill have a look. It looks like you are just getting some syntax errors.
Haha, thanks James. If you’re willing to help some more then any ideas why the cube now falls through cube b? It doesnt pay attention to the collision like it did previously?
Or if you deleted your entire script (The void, and using stuff) Then just copy paste this code:
(Still C#)
using UnityEngine;
using System.Collections;
public class Collide : MonoBehaviour { /* Rename "Collide" to your current script name */
void OnTriggerEnter(Collider col)
{
if(col.tag == "Cube A") /* The tag the cube needs */
{
Debug.Log("Touched Cube A"); /* Tell the console they touched */
}
}
}
This code represents that the cube needs to have a tag called “Cube A”
And that the script itself needs to be named “Collide” I have shown where this can be changed using a comm