targetcollider.cs
630 Bytes
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class targetcollider : MonoBehaviour
{
public static targetcollider instance;
void Awake() {
if(instance == null) {
instance = this;
}
}
void OnTriggerEnter(Collider other) {
moveTarget();
}
public void moveTarget() {
Vector3 temp;
temp.x = Random.Range(-4.8f/2, 4.8f/2);
temp.y = Random.Range(1f/2, 3f/2);
temp.z = Random.Range(-4.8f/2, 4.8f/2);
transform.position = new Vector3(temp.x,temp.y,temp.z);
}
}