Виталя Курылёв
Мастер
(1215)
3 месяца назад
using UnityEngine;
public class CarController : MonoBehaviour
{
private Rigidbody _rb;
public float speed = 5f, finalSpeed = 15f;
private bool isClicked;
public Vector3 FinalPosition;
void Awake()
{
_rb = GetComponent<Rigidbody>();
}
void OnMouseDown()
{
isClicked = true;
}
void Update()
{
if (FinalPosition.x != 0)
transform.position = Vector3.MoveTowards(transform.position, FinalPosition, finalSpeed * Time.deltaTime);
transform.LookAt(FinalPosition); // Исправлено на LookAt
}
void FixedUpdate()
{
if (isClicked && FinalPosition.x == 0)
_rb.MovePosition(transform.position + Vector3.forward * speed * Time.fixedDeltaTime);
}
}
dhddh djkfdgjhjУченик (62)
3 месяца назад
Спасибо ошибка убралась но когда я запускаю игру у меня машина едет задом наперед а потом когда сворачивает едет нормально
Assets\Scripts\CarController.cs(25,19): error CS1061: 'Transform' does not contain a definition for 'LokAt' and no accessible extension method 'LokAt' accepting a first argument of type 'Transform' could be found (are you missing a using directive or an assembly reference?)
using UnityEngine;
public class CarController : MonoBehaviour
{
private Rigidbody _rb;
public float speed = 5f, finalSpeed = 15f;
private bool isClicked;
public Vector3 FinalPosition;
void Awake() {
_rb = GetComponent<Rigidbody>();
}
void OnMouseDown() {
isClicked = true;
}
void Update() {
if(FinalPosition.x != 0)
transform.position = Vector3.MoveTowards(transform.position, FinalPosition, finalSpeed * Time.deltaTime);
transform.LokAt(FinalPosition);
}
void FixedUpdate() {
if(isClicked && FinalPosition.x == 0)
_rb.MovePosition(transform.position + Vector3.forward * speed * Time.fixedDeltaTime);
}
}