Assets\Hover\HoverBoardControl.cs(177,47): error CS7036: There is no argument given that…
- User
Assets\Hover\HoverBoardControl.cs(177,47): error CS7036: There is no argument given that corresponds to the required formal parameter 'startPosition' of 'HoverboardGrindController.StartGrinding(GrindableSurface, Vector3, Vector3)'
using UnityEngine; using UnityEngine.UI;
[RequireComponent(typeof(Rigidbody))] public class HoverBoardControl : MonoBehaviour { [Header("Hover Settings")] public float hoverForce = 9.0f; public float hoverHeight = 2.0f; public GameObject[] hoverPoints;
[Header("Movement Settings")] public float forwardAcceleration = 100.0f; public float backwardAcceleration = 25.0f; public float turnStrength = 10f; [Header("UI & Scoring")] public Text scoreText; public int currentScore; public HUD hud; // Ensure you have a HUD class in your project. public TrickManager trickManager; // Ensure you have a TrickManager class in your project. [Header("Boost Settings")] public float boostMultiplier = 2.0f; [Header("Rotation Settings")] public float minRotation = -20.0f; public float maxRotation = 0.0f; [Header("Timer Settings")] public float timer = 5.0f; [Header("Miscellaneous")] public bool moving; public GameObject board; [Header("Input Settings")] public KeyCode moveForwardKey = KeyCode.W; public KeyCode moveBackwardKey = KeyCode.S; public KeyCode turnLeftKey = KeyCode.A; public KeyCode turnRightKey = KeyCode.D; [Header("Customizable Keys")] [SerializeField] private KeyCode ollieKey = KeyCode.Space; [SerializeField] private KeyCode boostKey = KeyCode.LeftControl; [SerializeField] private KeyCode grindKey = KeyCode.G; int layerMask; float currentThrust; float currentTurn; private Rigidbody rb; private HoverboardGrindController hoverboardGrindController; // Ensure you have a HoverboardGrindController class in your project. void Awake() { rb = GetComponent<Rigidbody>(); hud = FindObjectOfType<HUD>(); trickManager = GetComponent<TrickManager>(); hoverboardGrindController = GetComponent<HoverboardGrindController>(); } void Start() { layerMask = 1 << LayerMask.NameToLayer("Characters"); layerMask = ~layerMask; // Initialization with hoverForce and hoverHeight can be customized or removed if these properties are set in the Unity Editor. // hoverForce = 1500f; // hoverHeight = 6f; // Initialization with scoreText object. This requires "ScoreText" prefab to be located in Resources folder. if (scoreText == null) { GameObject canvas = GameObject.Find("Canvas"); if (canvas != null) { scoreText = Instantiate(Resources.Load("ScoreText", typeof(Text))) as Text; scoreText.transform.SetParent(canvas.transform, false); } else { Debug.LogError("Canvas not found. Make sure there is a Canvas GameObject in the scene."); } } } void OnEnable() { rb.isKinematic = false; rb.useGravity = true; } void OnDisable() { rb.velocity = Vector3.zero; rb.angularVelocity = Vector3.zero; rb.isKinematic = true; } void Update() { currentThrust = 0.0f; currentTurn = 0.0f; if (scoreText) { scoreText.text = currentScore + " Points"; } if (Input.GetKeyDown(ollieKey)) { trickManager.ExecuteOllieOrTrick(1500f); } if (hud != null) { if (Input.GetKeyDown(boostKey) && hud.BoostInt > 0) { forwardAcceleration *= boostMultiplier; backwardAcceleration *= boostMultiplier; } else if (Input.GetKeyUp(boostKey)) { forwardAcceleration /= boostMultiplier; backwardAcceleration /= boostMultiplier; } if (Input.GetKey(boostKey)) { hud.BoostInt -= 0.2f; } } Vector3 currentRotation = transform.rotation.eulerAngles; currentRotation.x = Mathf.Clamp(currentRotation.x, minRotation, maxRotation); currentRotation.z = Mathf.Clamp(currentRotation.z, minRotation, maxRotation); transform.rotation = Quaternion.Euler(currentRotation); float aclAxis = Input.GetAxis("Vertical"); if (aclAxis > 0.1f) { currentThrust = aclAxis * forwardAcceleration; } else if (aclAxis < -0.1f) { currentThrust = aclAxis * backwardAcceleration; } float turnAxis = Input.GetAxis("Horizontal"); if (Mathf.Abs(turnAxis) > 0.1f) { currentTurn = turnAxis; } if (Input.GetKeyDown(trickManager.kickflipKey)) { trickManager.ExecuteKickflip(); } else if (Input.GetKeyDown(trickManager.heelflipKey)) { trickManager.ExecuteHeelflip(); } else if (Input.GetKeyDown(trickManager.shoveItKey)) { trickManager.ExecuteShoveIt(); } if (Input.GetKeyDown(grindKey)) { Collider nearestSurfaceCollider = hoverboardGrindController.FindClosestGrindableSurface(); if (nearestSurfaceCollider != null) { GrindableSurface nearestSurface = nearestSurfaceCollider.GetComponent<GrindableSurface>(); if (nearestSurface != null) { hoverboardGrindController.StartGrinding(nearestSurface); } } } else if (Input.GetKeyUp(grindKey)) { hoverboardGrindController.EndGrinding(); } } void FixedUpdate() { ApplyHover(); ApplyMovement(); ApplyTurning(); } void ApplyHover() { for (int i = 0; i < hoverPoints.Length; i++) { var hoverPoint = hoverPoints[i]; RaycastHit hoverHit; if (Physics.Raycast(hoverPoint.transform.position, -Vector3.up, out hoverHit, hoverHeight, layerMask)) { rb.AddForceAtPosition(Vector3.up * hoverForce * (1.0f - (hoverHit.distance / hoverHeight)), hoverPoint.transform.position); } else { if (transform.position.y > hoverPoint.transform.position.y) { rb.AddForceAtPosition(hoverPoint.transform.up * hoverForce, hoverPoint.transform.position); } else { rb.AddForceAtPosition(hoverPoint.transform.up * -hoverForce, hoverPoint.transform.position); } } } } void ApplyMovement() { if (Mathf.Abs(currentThrust) > 0) { rb.AddForce(transform.forward * currentThrust); } } void ApplyTurning() { if (currentTurn > 0) { rb.AddRelativeTorque(Vector3.up * currentTurn * turnStrength); } else if (currentTurn < 0) { rb.AddRelativeTorque(Vector3.up * currentTurn * turnStrength); } } - Assistant
The error message you're receiving indicates that the method
StartGrinding()in theHoverboardGrindControllerclass expects arguments that you're not providing in your call toStartGrinding(nearestSurface).The
StartGrindingmethod signature as shown in your error message is: - User
- Assistant
The error you are seeing,
CS0029: Cannot implicitly convert type 'GrindableSurface' to 'UnityEngine.Collider', is occurring because the variablenearestSurfaceis of the typeGrindableSurface, and theStartGrindingmethod of thehoverboardGrindControllerexpects a parameter of type . - User
- Assistant
- User
- Assistant
I see where the confusion is coming from now. In the
HoverBoardControlscript, at this line:Collider nearestSurfaceCollider = hoverboardGrindController.FindClosestGrindableSurface();The variable name suggests that what's being returned by
FindClosestGrindableSurface()should be aCollider. However, given the method signature of , it actually returns a object. As such, the variable should be renamed to reflect that it is not a : - User
This should be ready for a copy-paste application. Please correct.
- Assistant
Sure, here's the corrected segment from your
HoverBoardControlscript, with the appropriate changes for a copy-paste application. Make sure that this section of code replaces the corresponding section in your existing script:void Update() { // ... (other code) ... if (Input.GetKeyDown(grindKey)) { // Correctly get the nearest surface as a GrindableSurface object GrindableSurface nearestSurface = hoverboardGrindController.FindClosestGrindableSurface(); if (nearestSurface != null) { // Trigger the StartGrinding with the correct parameters hoverboardGrindController.StartGrinding(nearestSurface, transform.position, rb.velocity); } } else if (Input.GetKeyUp(grindKey)) { // End grinding if the button is released hoverboardGrindController.EndGrinding(); } // ... (the rest of your Update method code) ... } // ... (rest of the HoverBoardControl class) ...