- Home /
Enemy instantiate script, vars not showing in Inspector and error I can't fix
I'm trying to write a script to Instantiate 1 enemy every time the player walks over the trigger. Should be simple stuff but I'm bogged down. First of all my public variables don't show up in the Inspector which hasn't happened to me before, and secondly I get an error from the Console I can't fix: "No appropriate version of "UnityEngine.Object.Instantiate" for the argument list "UnityEditor.PrefabType,UnityEngine.Vector3,UnityEngineVector£)"was found" although I've tried a variety of things and they seem to be the same as the Script Notes in the Manual and what other people have done in similar scripts. Here is my code. I'm sorry I've been told off for not displaying code correctly but no one has explained how to. Thank you
pragma strict
//attached to playercharacter
var enemyDalek : PrefabType; var enemyAppearsSound : AudioClip;
private var enemyIsHere : boolean = false;
function OnControllerColliderHit (hit : ControllerColliderHit) { if (hit.gameObject.tag == "enemyTrigger" && enemyIsHere == false){var newEnemy : PrefabType = Instantiate (enemyDalek, Vector3 (147.8815, 8.964525, -0.06121051),Vector3 (0, 0, 0)); audio.PlayOneShot(enemyAppearsSound); } }
@script RequireComponent(AudioSource)
Answer by RHD · Dec 17, 2012 at 01:11 AM
Now it'm trying a different idea but I'm getting the same problem, no public variables showing in the Inspector and the same error message. My code:
pragma strict
//attached to trigger
private var dalekIsHere : boolean = false; var dalek : Rigidbody; var instance : Rigidbody = Instantiate(dalek, transform.position, transform.rotation) as Rigidbody; var dalekAppearsSound : AudioClip;
function OnTriggerEnter (col : Collider){ if (col.gameObject.tag == "Player" && dalekIsHere == false){ var newDalek : Rigidbody = Instantiate (instance, Vector3 (147.8815, 8.964525, -0.06121051), Vector3 (0, 0, 0)); audio.PlayOneShot(dalekAppearsSound); }
}