How to make a cube (go to a certain position) after colliding with a plane?

i recently got unity 3D and i have started making a game consisting of 2 cubes trying to knock each other off the arena. i am having some trouble with making the cube detect collision with the plane underneath the arena which i want it to make the cube re spawn when ever it touches it.
i have done this so far:

using UnityEngine;
using System.Collections;

public class plz : MonoBehaviour
    {
        void OnCollisionEnter(Collision col)
        {
            if (col.gameObject.name == "Death")
            {
                transform.localposition = new Vector3 (10.56507f, -13.15086f, 9.080673f);
            }
        }
    }

PLEASE HELP!!

What exactly isn't working? Also, please place the code in correct formatting.

Hi, yes, gladly: 1. Version of WordPress is 4.9. 2. Version of Unity that I built my games were: 2017.2.0, 5.6.0, 5.5.1, 5.0.3 3. Release build, WebGL build of course 4. Yes they seem to work, but the Roll-A-Ball_5.5.1 doesn't work Anyways I ended up needing to iFrame the game, but would still be very interested in using your plugin

1 Answer

1

edited the answer to format the code correctly, in future use the “101010” button, it makes it easier to read :slight_smile:

why not just check the current height of the cube?

public Vector3 spawnPos = new Vector3(10,1,9);
public float deathHeight = -13f;
public int lives = 3; 
//these are all public so that you can change them in the editor

void Update()
{
if(transform.position.y < deathHeight)
{
lives --; //lose a life
transform.position = spawnPos; //move the object back to the spawn position
}

hope this helps in some way :slight_smile:

Hello Deadshot, I am still looking at the javascript. There is an issue with it loading the game. I am looking at the issue.