- Home /
Problem Solved by Own.
Instantiate Problem
Hai there, i have a character movement script for android platform. My character is working left, right, down, up.., i have to instantiate bomb(object) when i press bomb icon. I modify my web game script into mobile, here is the script.
// Create Bomb...
if (Bomb_Button.HitTest(Input.GetTouch(0).position))
{
if(Instance == true)
{
Bomb_Temp = Instantiate (Bomb, Bomb_Place.transform.position, Quaternion.Euler (0, 0, 0)) as GameObject;
Explosion_Position = Bomb_Temp.transform.position;
Explosion_Rotation = Bomb_Temp.transform.rotation;
Bomb_Click = true;
Instance = false;
Expose_Instance = true;
}
}
if(Bomb_Click == true)
{
Bomb_Time += Time.deltaTime;
if(Bomb_Time >= 3f)
{
Destroy(Bomb_Temp);
Bomb_Time = 0;
Bomb_Click = false;
Bomb_Visible = true;
}
}
if(Bomb_Visible == true)
{
if(Expose_Instance == true)
{
audio.PlayOneShot (Explosion_Sound);
Explosion_Temp = Instantiate (Explosion, Explosion_Position, Explosion_Rotation)as GameObject;
Expose_Instance = false;
}
Explosion_Time += Time.deltaTime;
if(Explosion_Time >= 2f)
{
Destroy(Explosion_Temp);
Explosion_Time = 0;
Bomb_Visible = false;
Instance = true;
}
}
Actually i used this same script for my web platform(Changing controls into keyboard), working perfectly with that.
-Prasanna
And what is the problem now? Are there any errors in the console?
Have you tried GameObject.Instantiate ? And please, please don't post this meter long codes here. Try to strip that parts away that we don't need to solve your porblem. We are trying our best but here we can't help much.
Sorry for the long strip, actually i found the mistake. I forget to assign true for my Instance.
and now i have another problem, my instantiate timer for game and explosion is not working ususal. When i using web i used space key to instantiate the bomb, after i pressed space bomb will instantiate quickly and i automatically destroy after 3 seconds and my explosion get instantiate and it will destroy after some seconds. But when am using mobile it create bomb but its not destroy after 3 seconds(timer freeze actually.?) if i holding my button it destroy after some seconds and create explosion after that it need me to keep pressing the key..
-Prasanna
I have edited my question. this is the snippet for bomb instantiation.
Answer by robertbu · Aug 11, 2014 at 01:34 PM
You don't ask a question, nor explain what this script is doing or not doing. One problem is that you can only create a bomb if 'Instance' is true, but the only place you set it to true is on line 233 which I believe is your explosion code. Maybe 'Instance' should be initialized to 'true' on line 39.