When i run this script and the objects collide unity tells me i have failed to assign my prefab correctly(giving me the error “The Variable Cubeprefab of ‘Cubeinteractions’ has not been assigned” the moment there is a Collision). Any one care to help the scripting illiterate?
using UnityEngine;
using System.Collections;
public class Cubeinteractions : MonoBehaviour {
public Rigidbody Cubeprefab;
void OnCollisionEnter(Collision collisioninfo){
float boxmass = collisioninfo.rigidbody.mass;
if(boxmass == rigidbody.mass){
GameObject boxgameobject = collisioninfo.gameObject;
Rigidbody Cube1 = Instantiate(Cubeprefab, transform.position, transform.rotation) as Rigidbody;
Destroy(boxgameobject);
Destroy (gameObject);
}
}
}
I assume the problem is here “public Rigidbody Cubeprefab;”