I am trying to make the floating recources in my game send their name to my mining cube GameObjects when they are clicked.
Here’s my code:
using UnityEngine;
using System.Collections;
public class drift : MonoBehaviour {
private Vector3 torque;
private Vector3 drifting;
public Object cubes;
// Use this for initialization
void Start () {
torque = new Vector3 (Random.Range (-45.0F, 30.0F), Random.Range (-37.0F, 38.0F), Random.Range (-30.0F, 45.0F)) * 10 * Time.deltaTime;
drifting = new Vector3 (Random.Range (-1.0F, 1.0F), Random.Range (-1.0F, 1.0F), Random.Range (-1.0F, 1.0F)) * 10 * Time.deltaTime;
rigidbody.AddTorque (torque);
rigidbody.AddForce (drifting*50);
}
void OnMouseDown () {
cubes = GameObject.FindGameObjectsWithTag("player");
foreach (Object player in cubes) {
GetComponent<highlight> ().targetraw = gameObject;
}
}
}