- Home /
 
               Question by 
               RestitutorOrbis · Dec 28, 2020 at 08:19 PM · 
                unity 5destroywebglbullet  
              
 
              2d bullets not working in WebGL, but works fine in Unity Editor/Play
I'm making a 2d tower defense game and getting weird behavior with the bullets, but only when it runs in WebGL
Basically, my towers instantiate bullets and transform their position toward the enemy:
 void Update()
     {
         if (set == true)
         {
             //move bullet to target position
             float timeInterval = Time.time - startTime;
             gameObject.transform.position = Vector3.Lerp(startPosition, targetPosition, timeInterval * speed / distance);
 
             //apply damage on hit 
             if (gameObject.transform.position.Equals(targetPosition))
             {
                 if (target != null)
                 {
 
 
                     int randomCrit = Random.Range(0, 100); // choose random # between 0 and 99
                     if (randomCrit < critChance)
                     {
                         target.GetComponent<EnemyController>().criticalHit(); // critical hit
                         target.GetComponent<EnemyController>().currentHP -= damage * critMultiplier;
                     }
                     else
                         target.GetComponent<EnemyController>().currentHP -= damage; //normal damage
                     target.GetComponent<EnemyController>().lastHitFrom = towerThatCreatedBullet;
 
                 }
                 Destroy(gameObject);
             }
         }        
     }
It works great in the Unity Editor.
The weird thing is, when it runs in WebGL, sometimes, but not all the time (seemingly random, say about 50% of the time) the bullet reaches the target, but applies no damage, and then it just sits there in place and Destroy(gameobject) never runs.
 So I'm thinking this statement: if (gameObject.transform.position.Equals(targetPosition)) never equates to True, but only in WebGL. 
 Does anyone have any thoughts on why this might be happening? 
 Thanks in advance!!
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                