- Home /
[Closed] "The regerenced script on the Behavior is missing!"
I have no idea what it's talking about, I don't see anything wrong with my code.
using UnityEngine;
using System.Collections;
public class ENAI : MonoBehaviour {
// Use this for initialization
void Start () {
InvokeRepeating("SpawnEnemy",1,1);
}
// Update is called once per frame
void SpawnEnemy () {
int rndizer = Random.Range(1, 51);
if (rndizer == 1 ) {
Rigidbody clone;
clone = Instantiate (GameObject.Find ("Enemy"), transform.position, transform.rotation) as Rigidbody;
clone.AddForce (Vector3.forward / 40);
}
}
}
Comment
Best Answer
Answer by digibawb · Sep 07, 2014 at 12:46 AM
When you call GameObject.Find, this will return a GameObject.
When you call Instantiate on this GameObject, this will also return a GameObject, so your cast with 'as' will not return a valid rigid body.
You should store the GameObject returned and use GetComponent to access the RigidBody.
Your answer
Follow this Question
Related Questions
getting udp package info inside unity (GlovePIE) 0 Answers
Collision Causing Lag? 1 Answer
Why doesnt my script work 2 Answers
Game crashes! 1 Answer
Unity error CS1014 1 Answer