- Home /
Spawn script on mesh crashes Unity
Hi :) I´m working on a survival game on a planet. My spawn script for trees is already woring well on a regular sphere, but i want my planet to be an irregular mesh so I created another script. Now everytime I run the game Unity crashes. Can you help me out? (Maybe the if in line 21 is the problem ...)
Thank you TheSakuron
Here is my script for the irregular mesh : .`using UnityEngine; using System.Collections;
public class EnvironmentSpawner : MonoBehaviour {
public GameObject Planet;
public GameObject tree;
public GameObject PlanetOrigin;
public float UnicornCloudDistance;
public float TreeNumber;
public float MinSize;
public float MaxSize;
void Start () {
for(int i=0; i<TreeNumber;i++) {
Vector3 origin = PlanetOrigin.gameObject.transform.position;
Vector3 UnicornCloud = Random.onUnitSphere * UnicornCloudDistance;
RaycastHit hit;
Physics.Linecast(UnicornCloud,origin, out hit);
var HitCollider = hit.collider;
var PlanetName = Planet.collider;
if(PlanetName == HitCollider) {
Vector3 onPlanet = hit.point;
var RandomSize = Random.Range(MinSize,MaxSize);
GameObject Baum = Instantiate(tree, onPlanet, Quaternion.identity) as GameObject;
Baum.transform.localScale = Vector3.one * RandomSize;
Baum.transform.LookAt(PlanetOrigin.transform.position);
Baum.transform.rotation = Baum.transform.rotation*Quaternion.Euler(-90, 0 , 0);
}
else {
i--;
Debug.Log("Tree set to new Position!");
}
}
}
}`
Comment
Your answer
Follow this Question
Related Questions
How can I improve this code? 1 Answer
How to find connected mesh triangles? 2 Answers
Raycast crashing build on collision with mesh collider 3 Answers
How to create a mesh with coordinates given from an Arduino? 1 Answer
Spawn a mesh in terrain 1 Answer