public override void Update(Blastball blastball) { //check collisions bool checkSphere = Physics.CheckSphere(blastball.transform.position, blastball.transform.lossyScale.x / 2, playerMask); Physics.OverlapSphereNonAlloc(blastball.transform.position, blastball.transform.lossyScale.x / 2, overlapPlayer, playerMask); //store the last player to have the blastball to prevent them from passing it to themselves //TODO: theoretically, there could be a *rare* bug if the ball collides with two players at the exact same time, so prioritize players of the same team as the thrower and then randomly pick between them, but doubtful this will happen often, if at all if (!oldCheckSphere && checkSphere && overlapPlayer[0] != oldPlayer) //check collision OnEnter and make sure the collision is with a new player { increment++; //upon being passed, the blastball increments Debug.Log("incrementing"); renderer.material.SetColor("_Color", Color.Lerp(minColor, maxColor, increment / Blastball.MaxIncrement)); //lerp blastball color as it increments renderer.material.SetColor("_EmissionColor", Color.Lerp(minColor, maxColor, increment / Blastball.MaxIncrement)); //lerp blastball emission color as it increments blastball.transform.localScale = Vector3.Lerp(minSize, maxSize, increment / Blastball.MaxIncrement); //lerp blastball size as it increments rb.mass = Mathf.Lerp(minMass, maxMass, increment / Blastball.MaxIncrement); oldPlayer = overlapPlayer[0]; //set the player who has the ball as the old player Debug.Log(oldPlayer.gameObject); } oldCheckSphere = checkSphere; //change state if (increment >= Blastball.MaxIncrement) { blastball.ChangeState(blastball.stateBlastOnImpact); } else if (increment > oldIncrement) { blastball.ChangeState(blastball.stateIdle); } }