/// <summary> /// Hits the ball on the host. /// </summary> /// <param name="code">The message data from the packets.</param> internal void UpdateBalls(string code) { SerializationScript.BallShot ballShot = SerializationScript.DeserializeBallShot(code); GameObject ball = ballShot.isAbilityBall ? golfBallManager.GetAbilityBallOfId(ballShot.ballID) : golfBallManager.GetBallOfId(ballShot.ballID); BallRetrieval br = ball.GetComponent <BallRetrieval>(); ball.GetComponent <Rigidbody>().velocity = ballShot.direction; if (br) { ball.GetComponent <BallRetrieval>().SetNewBallPos(); } GolfBall golf = ball.GetComponent <GolfBall>(); golf.HitBall(ballShot.shooterID, network.IsHost()); if (network.IsHost()) { if (golf.IsAbilityBall()) { MovingAbilityBalls.Add(golf); } if (ballShot.shouldHome) { Honing theHone = ball.gameObject.GetComponent <Honing>(); if (theHone != null && ballShot.homingTargetID >= 0) { theHone.HoneToPlayer(network.GetPlayerOfID(ballShot.homingTargetID)); } } } }
IEnumerator NoNetworkingWaitForSwing(GolfBall golfBall, Vector3 dir) { while (!swing) { yield return(new WaitForEndOfFrame()); } golfBall.GetComponent <Rigidbody>().velocity = dir; if (clubStats.ClubName == "Driver") { Honing theHone = golfBall.gameObject.GetComponent <Honing>(); GameObject obj = theHone?.GetObjOfClosestPlayer(); if (obj != null) { theHone.HoneToPlayer(obj); } } }
public void GolfSwing(GolfBall golfball) { if (!golfball || !IsPrepped) { return; } BallRetrieval br = golfball.GetComponent <BallRetrieval>(); float power = Mathf.Lerp(clubStats.MinDistance, clubStats.MaxDistance, powerOnRelease / clubStats.TimeForMaxDistance); if (br) { golfball.GetComponent <BallRetrieval>().SetNewBallPos(); } Vector3 dir = transform.root.forward; dir = Vector3.RotateTowards(dir, new Vector3(dir.x, dir.y + clubStats.VectorYIncrease, dir.z), 1, 0.0f); dir = dir.normalized * power; if (!NetworkManager.instance) { StartCoroutine(NoNetworkingWaitForSwing(golfball, dir)); } else { int id = golfball.IsAbilityBall() ? -1 : golfball.gameObject.transform.GetSiblingIndex(); int targetID = -1; Honing theHone = golfball.gameObject.GetComponent <Honing>(); if (clubStats.ClubName == "Driver" && theHone != null) { targetID = theHone.GetIDOfClosestPlayer(); } StartCoroutine(NetworkingWaitForSwing(golfball.gameObject, id, dir, golfball.IsAbilityBall(), clubStats.ClubName == "Driver", targetID)); } StartCoroutine(WaitForSwing(golfball, clubStats, power)); }