Quantcast
Channel: Questions in topic: "webgl"
Viewing all articles
Browse latest Browse all 2390

2d bullets not working in WebGL, but works fine in Unity Editor/Play

$
0
0
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().criticalHit(); // critical hit target.GetComponent().currentHP -= damage * critMultiplier; } else target.GetComponent().currentHP -= damage; //normal damage target.GetComponent().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!!

Viewing all articles
Browse latest Browse all 2390

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>