I have a sphere trigger attached to an object that over .25 seconds scales larger, and disappears when finished growing. This trigger is supposed to fire off a script when a specific object collides with it. The problem is that its producing inconsistent results when it reaches its max radius. With the objects stationary at the outer radius sometimes it picks them up and sometimes it doesn’t. Here is the code:
void Update()
{
time += Time.deltaTime;
float atkScale = (time / .25f) * maxScale;
if (atkScale >= maxScale)
atkScale = maxScale;
transform.localScale = new Vector3(atkScale, 1f, atkScale);
if (atkScale == maxScale)
{
gameObject.SetActive(false);
}
}
private void OnTriggerEnter(Collider col)
{
if (col.gameObject.layer == GetEnemyLayer())
{
if (!enemiesHit.Contains(col.gameObject))
{
CollisionScript();
enemiesHit.Add(col.gameObject);
}
}
}
Is it possible to get this to produce consistent results?