- Home /
Cast a variable over intentiated gameObjects
Hello commUnity ;D
Here's my problem : I'm programming a multiplayer (network) Bomberman, and i'm getting stuck on a simple bomb x_x A player can drop a bomb, which wait a certain time before spawning explosions and destroy itself.
The explosion move one case forward (all the explosion are spawned with the good rotation) and do the same as the bomb : spawning another explosion (range) and destroying (all that in the same frame). The problem is that I can't put a variable "Power" and give it to each explosion, that will decrease it each time they spawn another one, so that I can control the range of the explosion (like in an old school Bomberman).
Here is the two scripts involved in this behavior: BombScript:
var blast : Transform;
var power : float = 2;
private var rotationright = Quaternion.identity;
private var rotationleft = Quaternion.identity;
private var rotationdown = Quaternion.identity;
function Start(){
networkView.RPC("DestroyIt",RPCMode.AllBuffered);
rotationdroite.eulerAngles=Vector3(0,90,0);
rotationgauche.eulerAngles=Vector3(0,-90,0);
rotationbas.eulerAngles=Vector3(0,180,0);
}
function Update () {
}
@RPC
function DestroyIt(){
yield WaitForSeconds(2);
//Network.Instantiate(blast,transform.position,transform.rotation,3);
//Network.Instantiate(blast,transform.position,rotationright,3);
//Network.Instantiate(blast,transform.position,rotationleft,3);
Network.Instantiate(blast,transform.position,rotationdown,3);
blast.gameObject.SendMessage("Power",power,SendMessageOptions.DontRequireReceiver);
//Destroy (gameObject);
}
And the explosion Script :
private var exploded : boolean = true;
var blast : Transform;
private var power : float;
function Start(){
transform.position += transform.forward;
networkView.RPC("Explode",RPCMode.AllBuffered);
}
function Update () {
Debug.Log(power+"is the power");
}
function OnTriggerEnter(collision : Collider) {
if(collision.gameObject.tag =="Player"){
collision.gameObject.transform.SendMessage("TakeExplosion",exploded,SendMessageOptions.DontRequireReceiver);
} }
function Power(info : float){
power = info;
}
@RPC
function Explode(){
Network.Instantiate(blast,transform.position,transform.rotation,4);
yield WaitForSeconds(0.2);
Destroy (gameObject);
}
And here a little fluffy drawing that sums up my goal ^^ Thank you, any help is appreciated :p (Btw, forget my not so good english, i'm French +_+)
Your answer
Follow this Question
Related Questions
How to create a object that can only be seen by one player? 0 Answers
Setting the variable on a GameObject to be instantiated (not yet existent) cs and js 2 Answers
Help! My projectile just falls to the ground :( 1 Answer
Assigning gameobject to an instantiated prefab through script? 2 Answers
sync tags through network? 0 Answers