{
public GameObject power;
GameObject[] ins = new GameObject[100];
BoxCollider2D collider;
bool once = true;
public playermove script;
public GameObject player;
public int amount = 20;
public GameObject button;
public GameObject mouse;
public Camera cam;
Vector2 mousepos;
BoxCollider2D mousecol;
public static bool buttonpressed;
int objectamount = 0;
// Start is called before the first frame update
void Start()
{
mousecol = mouse.GetComponent<BoxCollider2D>();
}
// Update is called once per frame
void Update()
{
if (playermove.alive)
{
InvokeRepeating("generate", 3, 3);
}
if (buttonpressed)
{
butclicked();
}
}
private void OnTriggerEnter2D(Collider2D collider)
{
if (collider.gameObject.tag == "Player")
{
playermove.amount = 5;
Destroy(gameObject);
objectamount--;
}
}
void generate()
{
if(objectamount < 30)
{
Instantiate(power);
objectamount ;
}
if(gameObject.transform.position.x < player.transform.position.x - 90 || gameObject.transform.position.x < player.transform.position.x 90)
{
Vector2 pos = gameObject.transform.position;
pos.x = player.transform.position.x Random.Range(-90, 90);
pos.y = 100 / Random.Range(1f, 10f);
gameObject.transform.position = pos;
}
}
public void clonestart()
{
for (int i = 0; i < 30; i )
{
objectamount ;
Instantiate(power);
Vector2 startpos = transform.position;
startpos.x = player.transform.position.x Random.Range(-30, 30);
startpos.y = i 100 / Random.Range(1f, 10f);
gameObject.transform.position = startpos;
//Debug.Log(playermove.alive);
}
}
public void butclicked()
{
if (playermove.alive == false)
{
Debug.Log("wtf");
playermove.alive = true;
clonestart();
}
}
}
clonestart() function gets called even when playermove.alive == true and I have debug.loged the playermove.alive and it is true whenever I debug it and the if statemet for everything else works fine but ive tried everything and even in other scripts I'm having the same issue is anyone elses having the same issue? or does anyone know how to fix the issue?
CodePudding user response:
It's true when you debug it because you set it to true before calling clonestart()
CodePudding user response:
I icant comment so I typing here
So you say you wan start clonestart() function when buttun clicked and player is not alive ,try this
if (playermove.alive == false &&buttonpressed==true)
{
Debug.Log("wtf");
// playermove.alive = true;
buttonpressed = false
clonestart();
}
