- Home /
bullet problem
ok so this is my complete script on main object that has a spawnPoint for the bullet to spawn from t he bulletprefab is tagged and the bullet itself it fine
this also causes my unity to crash from time to time
the script is forming the bullet but the bullet isnt going anywhere and im getting this error
"Missing Field Expection: field unity engine. transform.tag not found" boo.lang.runtime.dynamicdispatching.propertydispatcherfactory.findextension (error line 15)
var speed : int = 5;
var rotateSpeed : int = 3;
static var bullets : int = 10;
var timer :float;
var bulletPrefab : Transform;
function Start () {
while(true){
while(!Input.GetButtonDown("Jump"))yield;
bullet = Instantiate(bulletPrefab, GameObject.Find("spawnPoint").transform.position, transform.rotation);
bullet.Tag = "bulletPrefab";
bullet.rigidbody.AddForce(bullet.forward *400);
}
}
function Update () {
var controller : CharacterController = GetComponent(CharacterController);
transform.Rotate(0, Input.GetAxis ("Horizontal") *rotateSpeed, 0);
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis("Vertical");
controller.SimpleMove(forward * curSpeed);
}
function OnGUI(){
GUI.Label(Rect(10,10,200,50), "Timer:" + timer);
GUI.Label(Rect(10,30,200,50), "Bullets left:" + bullets);
}
umm i think it was that it cant fine the tag bulletPrefab
but i cnt check that as it keep crashing everytime i press space
make a stand alone of your game, go and run it, check the data folder for output_log.txt, see if it contains the error in there. You can also comment out some of the lines of code starting from the bottom when you addforce, try and narrow down the problem. You setting the tag shouldn't be an issue, what script is trying to find the tag? is it happening when the bullet collides with something? You don't give much information as to the use case for your single function you posted.
Does it crash right when you hit space bar? does the bullet actually move on the screen?
You could try using an if statement in the update function, that might stop your unity from crashing.
like this:
function Update () {
if(Input.GetButtonDown("Jump")){
bullet = Instantiate(bulletPrefab, GameObject.Find("spawnPoint").transform.position, transform.rotation);
bullet.tag = "bulletPrefab";
bullet.rigidbody.AddForce(bullet.forward *400);
}
}
im not sure why but its stopped crashing now which is helpful Landern i have also update everything with some more information
Answer by Sooper1337 · Oct 23, 2012 at 05:41 PM
You could try using an if statement in the update function, that might stop your unity from crashing.
like this:
function Update () {
if(Input.GetButtonDown("Jump")){
bullet = Instantiate(bulletPrefab, GameObject.Find("spawnPoint").transform.position, transform.rotation);
bullet.tag = "bulletPrefab";
bullet.rigidbody.AddForce(bullet.forward *400);
}
}
ive stopped it crashing but i dnt know what this error is or how to stop it also my bullet isnt going any where its just still
$$anonymous$$issing Field Expection: field unity engine. transform.tag not found" boo.lang.runtime.dynamicdispatching.propertydispatcherfactory.findextension (error line 15)
Your answer
Follow this Question
Related Questions
Bullet Script 2 Answers
object referance problem with bullet adding 1 Answer
2D bullet script errors. 1 Answer
Instantiate bullet hit enemy aim error 0 Answers
The code is giving me errors 1 Answer