I have 10 prefabs spawning in random directions at different sizes, but as soon as they spawn they move constantly off into the distance. Please help me figure out what I’m doing wrong, thanks!
using UnityEngine;
using System.Collections;
public class MakeIslands : MonoBehaviour {
public GameObject island;
// Use this for initialization
void Start () {
for (var x = 0; x < 10; x++) {
GameObject islandClone = Instantiate(Resources.Load("Island"), randoVector, transform.rotation) as GameObject;
}
}
// Update is called once per frame
void Update () {
}
}
/////////////////////////
using UnityEngine;
using System.Collections;
public class IslandHealth : MonoBehaviour {
int islandHealth = 100;
bool shipCollide = false;
// Use this for initialization
void Start () {
int islandSizeXZ = Random.Range (1, 5);
int islandSizeY = Random.Range (1, 5);
int islandX = Random.Range (-10, 10);
int islandY = Random.Range (20, 40);
int islandZ = Random.Range (-10, 10);
transform.localScale += new Vector3 (islandSizeXZ, islandSizeY, islandSizeXZ);
transform.position = new Vector3 (islandX, islandY, islandZ);
islandHealth = Mathf.Abs (islandSizeXZ * islandSizeY);
rigidbody.useGravity = false;
}
// Update is called once per frame
void Update () {
if (islandHealth <= 0) {
Destroy(this.gameObject);
}
//viewDistance ();
}
void OnCollisionEnter(Collision col){
if (col.gameObject.name == "Ship") {
islandHealth = islandHealth - 10;
}
if (col.gameObject.name == "Daylight Simple Water") {
islandHealth = 0;
}
if (col.gameObject.name == "Island") {
islandHealth = 0;
}
}
void viewDistance(){
var distance = Vector3.Distance(this.gameObject.transform.position, GameObject.FindGameObjectWithTag("Ship").transform.position);
if (distance > 100) {
Destroy(this.gameObject);
}
}
void OnGUI () {
//GUI.Label (new Rect (0, 750, 600, 300), "Island currently at:" + transform.position);
}
}