I have a question, if you have a float variable “WaitTime” which has 6.0f for its value, then you passed this variable in yield return new WaitForWeconds(Waittime) , Does “WaitTime” get reset to 0.0f . Thanks for answering
No, the variable’s value remains unchanged.
but why when I run this script
void OnTriggerEnter2D(Collider2D Collide){
if (Collide.gameObject.tag == "Turret") {
Once=true;
SelfAnimator.SetInteger("Upgrade",Upgrade);
SelfAnimator.SetBool("Hit",false);
DerivedBullet();
}
if (Collide.gameObject.tag == "Enemy") { //Look Here
Debug.Log("Hit");
SelfAnimator.SetBool("Hit",true);
Rigid2D.velocity=new Vector2(0.0f,0.0f);
StartCoroutine(base.CountingTime()); //I this coroutine I didn't make any change with "Waittime"
Debug.Log(Waittime); //*******This Tells my Waittime which has a value of 6.0f at first then 0.1f after 1 frame why is it***
}
}
That means you are modifying Waittime somewhere.
This is the base class with all the variable “Waittime” inside I didn’t modified the “Waittime” variable in this script
protected virtual IEnumerator CountingTime(){
yield return new WaitForSeconds (Waittime); //*********Waittime #1
transform.position = OriginPosi;
BoxCol2D.enabled=true;
gameObject.SetActive (false);
yield return null;
}
protected virtual void OnTriggerEnter2D(Collider2D Collid){
TempGameObj = Collid.gameObject;
if (Collid.gameObject.tag == "Turret") {
StartCoroutine ("BulletCoroutine");
StopCoroutine("BulletCoroutine");
}else if(Collid.gameObject.tag=="Building"){
transform.position = OriginPosi;
BoxCol2D.enabled=true;
gameObject.SetActive (false);
}
else if (Collid.gameObject.layer == 8) {//Normal
SelfAnimator.Play("NormalNor");
Waittime=0.25f; //*********Waittime #2
Rigb2D.velocity =new Vector2(0.0f,0.0f);
BoxCol2D.enabled=false;
StartCoroutine("CountingTime");
}
else if (Collid.gameObject.layer == 9 ) { //Swarmer
SelfAnimator.Play("NormalSwar");
BoxCol2D.enabled=false;
Waittime=0.25f; //*********Waittime #3
Rigb2D.velocity =new Vector2(0.0f,0.0f);
}
else if (Collid.gameObject.layer == 10) { //Rocker
SelfAnimator.Play("NormalRock");
BoxCol2D.enabled=false;
Waittime=0.25f; //*********Waittime #4
Rigb2D.velocity =new Vector2(0.0f,0.0f);
}
else if (Collid.gameObject.layer == 11) { //Shield
SelfAnimator.Play("NormalShie");
Waittime=0.25f; //*********Waittime #5
BoxCol2D.enabled=false;
StartCoroutine("CountingTime");
Rigb2D.velocity =new Vector2(0.0f,0.0f);
}
}
Is Waittime a static variable? Maybe you are changing it in an other script.
You are obviously not showing the whole script. That would help a lot.