Question by
kramarczukadrian · Aug 03, 2020 at 11:25 AM ·
scripting problemgameobjectcollidersissuevehicle
MissingReferenceException: The variable (name) of (script) doesn't exist anymore.
I'm a new Unity user and I'm having an issue with my vehicle movement script. The problem arises when I want to rotate the wheel. It says line 42 but I don't see an issue.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(InputManager))]
[RequireComponent(typeof(Rigidbody))]
public class SnowmobileController : MonoBehaviour
{
public InputManager im;
public List<WheelCollider> throttleWheels;
public List<GameObject> steeringWheels;
public List<GameObject> meshes;
public float strengthCoefficient = 20000f;
public float maxTurn = 20f;
public Transform CM;
public Rigidbody rb;
// Start is called before the first frame update
void Start()
{
im = GetComponent<InputManager>();
rb = GetComponent<Rigidbody>();
if (CM)
{
rb.centerOfMass = CM.position;
}
}
// Update is called once per frame
void Update()
{
foreach (WheelCollider wheel in throttleWheels)
{
wheel.motorTorque = strengthCoefficient * Time.deltaTime * im.throttle;
}
foreach (GameObject wheel in steeringWheels)
{
wheel.GetComponent<WheelCollider>().steerAngle = maxTurn * im.steer;
wheel.transform.localEulerAngles = new Vector3(0f, im.steer * maxTurn, 0f);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Roll a ball and quiz (Pause scene, load scene and resume) 0 Answers
How to change value of another gameobject through script 2 Answers
How to play audio while reloading a weapon ammo in unity 3d C# Scripting ? 0 Answers
Put a GameObject in the script's inspector when the script belongs to a prefab 1 Answer
Script behaves strangely 1 Answer