Q:I have a fort, I have four bullets,different filling time for each bullet.
If twenty seconds time is up ,bullets fired automatically. But do not know which bullet was fired.
How to write this script? Can give some idea?
Q:I have a fort, I have four bullets,different filling time for each bullet.
If twenty seconds time is up ,bullets fired automatically. But do not know which bullet was fired.
How to write this script? Can give some idea?
Ok, although you should reformulate the question, I will answer it.
ok so…we got 4 bullets with a different filling time, but they still fire after 20 secs…hmmm
ok I’m not going to write the hole script.
var time : int = 20;
var bullet1 : Transform;
var bullet2 : Transform;
var bullet3 : Transform;
var bullet4 : Transform;
private var picking : int;
function Update(){
Invoke("Fire" 20);
}
function Fire(){
picking = Random.Range(0, 3);
if(picking == 0){
Instantiate(bullet1, instantiating shit);
}
if(picking == 1){
Instantiate(bullet2, instantiating shit);
}
if(picking == 2){
Instantiate(bullet3, instantiating shit);
}
if(picking == 3){
Instantiate(bullet4, instantiating shit);
}
}
Ok this should do it, don’t forget to add the force to the bullet.
Let me explain quickly how this works.
So what Invoke does is it calls a certain function in a certain amount of time.
after thats done, the picking var chooses between 4 numbers that can vary between 0 and 3.
evry number has its respective bullet.
As you can see 0=bullet1, 1=bullet2, 2=bullet3, 3=bullet4
If you find this confusing instead of:
Random.Range(0, 3);
Use
Random.Range(1,4);
So thats about it, if you have any questions plz comment. Oh, and don’t forget instead of writing “I have a question” actually write the subject of the problem.
-Hybris