i new to this c#
i try to make an object to move but instate i got null reference expception
this is my script
using UnityEngine;
using System.Collections;
public class motor : MonoBehaviour
{
public float moveSpeed = 5.0f;
public float drag = 0.5f;
public float terminalRotationSpeed = 25.0f;
public virtualjoystick moveJoystick;
private Rigidbody controller;
private Transform camTransform;
private void Start()
{
controller = GetComponent<Rigidbody>();
controller.maxAngularVelocity = terminalRotationSpeed;
controller.drag = drag;
camTransform = Camera.main.transform;
}
private void Update()
{
Vector3 dir = Vector3.zero;
dir.x = Input.GetAxis("Horizontal");
dir.z = Input.GetAxis("Vertical");
if (dir.magnitude > 1)
dir.Normalize();
if (moveJoystick.InputDirection != Vector3.zero)
{
dir = moveJoystick.InputDirection;
}
// Rotate our direction vector with camera
Vector3 rotatedDir = camTransform.TransformDirection(dir);
rotatedDir = new Vector3(rotatedDir.x, 0, rotatedDir.z);
rotatedDir = rotatedDir.normalized * dir.magnitude;
controller.AddForce(rotatedDir * moveSpeed);
}
}
i got that error in line 39 that is the = Vector3 rotatedDir = camTransform.TransformDirection(dir);