Here are 2 scripts, can you update the 1st with the changes from the 2nd please and then…
- User
Here are 2 scripts, can you update the 1st with the changes from the 2nd please and then provide me the complete edited script retaining all logic etc? Script 1 using UnityEngine; using UnityEngine.UI;
public class PlayerGrindController : MonoBehaviour { [Header("Grind Settings")] public float grindSpeed = 0.1f; public bool isGrinding;
public Transform grindPosition; // The target position on the grindable object public Transform localGrindDirection; // The direction of grinding (if needed) [Header("Grind UI")] public Slider grindBalanceSlider; // Assign this in the inspector private float grindBalance; // Represents the current balance while grinding private float grindBalanceTime = 4f; // Time after which the grind balance changes direction private bool continueGrinding; // Indicates if grinding should continue forward private bool intermediateMode; // Determines if the intermediate position is active private Transform intermediatePoint; // Optional intermediate grinding point private float balanceValue; // Randomly set value used to simulate balance change private void Update() { if (isGrinding) { GrindBalanceManager(); GrindMovement(); } } private void GrindBalanceManager() { // Modify the slider value over time and check if the player keeps their balance grindBalance += Time.deltaTime; if (grindBalance >= grindBalanceTime) { grindBalance = 0f; balanceValue = Random.Range(-30, 30); // Simulate a balance value change } // Example logic to move the grind balance slider towards the balanceValue grindBalanceSlider.value = Mathf.MoveTowards(grindBalanceSlider.value, balanceValue, 10f * Time.deltaTime); } private void GrindMovement() { if (continueGrinding) { // If in intermediate mode, move towards the intermediate point first if (intermediateMode) { if (Vector3.Distance(transform.position, intermediatePoint.position) <= 1.5f) { intermediateMode = false; } else { transform.position = Vector3.MoveTowards(transform.position, intermediatePoint.position, grindSpeed * Time.deltaTime); } } // Otherwise, move towards the main grind direction else { transform.position = Vector3.MoveTowards(transform.position, localGrindDirection.position, grindSpeed * Time.deltaTime); } } } public void OnTriggerEnter(Collider other) { if (other.CompareTag("GrindableSurface")) { StartGrinding(other.transform); } } public void OnTriggerExit(Collider other) { if (other.CompareTag("GrindableSurface")) { EndGrinding(); } } public void StartGrinding(Transform grindSurface) { isGrinding = true; continueGrinding = true; // Assign references or find child objects on the grindSurface to set up grinding grindPosition = grindSurface.GetChild(0); // Set this according to your grind object setup intermediatePoint = null; // Set this according to your grind object setup intermediateMode = false; // Set this according to your grind object setup localGrindDirection = grindSurface; // Example value, replace with actual alignment logic grindBalanceSlider.gameObject.SetActive(true); // Show the slider when grinding starts } public void EndGrinding() { isGrinding = false; continueGrinding = false; intermediateMode = false; grindBalanceSlider.gameObject.SetActive(false); // Hide the slider when grinding ends } - Assistant
- User
- Assistant