So, I have two bits of code that I’m using, “PlaceMine” & “StepOnMine.”
My goal is to have my “Player” place a Mine that will only destroy enemies who step on it.
What it is doing is playing the explosion sound as soon as the player places it. then it is totally unresponsive.
Thanks in advance for and help provided.
“PlaceMine” attached to my player and appears to work correctly.
using UnityEngine;
using System.Collections.Generic;
public class PlaceMine : MonoBehaviour
{
// Gets the gameObject
public Object mine;
// Gets the input key
public string placeMine = "space";
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown (placeMine)) {
Instantiate (mine, this.transform.position, this.transform.rotation);
}
}
}
“StepOnMine” is attached to my land Mine and is playing sound as soon as I place it. After that it appears to be totally unresponsive.
using UnityEngine;
using System.Collections;
public class StepOnMine : MonoBehaviour
{
// check for collision and detect collider
void OnCollision (Collider col)
{
//if a collider tag is not equal to gameObject with the tag "Player"
if (col.gameObject.tag != "Player") {
// get audio file
AudioSource audio = GetComponent<AudioSource> ();
// play audio file
audio.Play ();
// destroy collider
Destroy (col.gameObject);
// destroy itself
Destroy (this.gameObject);
}
}
}