Скрипт касания игрока машиной, переделывание префабов
This commit is contained in:
@ -13,9 +13,29 @@ public class CarControllerScript : MonoBehaviour
|
||||
[SerializeField]
|
||||
private List<GameObject> _Wheels = new List<GameObject>();
|
||||
|
||||
/// <summary>
|
||||
/// to do
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
private int _Speed;
|
||||
|
||||
/// <summary>
|
||||
/// высота,чтобы колёса стояли на 0
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
private float _High;
|
||||
|
||||
public float High
|
||||
{
|
||||
get => _High;
|
||||
set => _High = value;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_High = gameObject.transform.position.y;
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
foreach (var wheel in _Wheels)
|
||||
@ -23,4 +43,6 @@ public class CarControllerScript : MonoBehaviour
|
||||
wheel.transform.Rotate(Vector3.right * _Speed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,14 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CarManagerScript : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private int _MaxSpeed;
|
||||
|
||||
private int _Speed;
|
||||
|
||||
[SerializeField]
|
||||
private List<GameObject> _CarPrefs;
|
||||
@ -17,12 +21,27 @@ public class CarManagerScript : MonoBehaviour
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_LeftToRight = GetRandomObject<bool>(new List<bool> { true, false });
|
||||
StartMove();
|
||||
}
|
||||
List<int> speedVar = new List<int>();
|
||||
|
||||
[SerializeField]
|
||||
private int _Speed;
|
||||
for(int i = _MaxSpeed/2; i <= _MaxSpeed; i++)
|
||||
{
|
||||
speedVar.Add(i);
|
||||
}
|
||||
|
||||
_Speed = GetRandomObject<int>(speedVar);
|
||||
|
||||
//Debug.Log($"Speed - {_Speed}");
|
||||
|
||||
_LeftToRight = GetRandomObject<bool>(new List<bool> { true, false });
|
||||
|
||||
float time = GetRandomObject<float>(new List<float> { 0f, 1f, 2f, 3f, 4f, 5f });
|
||||
|
||||
//Debug.Log(time);
|
||||
|
||||
Invoke("StartMove", time);
|
||||
|
||||
//Debug.Log("was spawned");
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
@ -36,6 +55,15 @@ public class CarManagerScript : MonoBehaviour
|
||||
{
|
||||
_Car.transform.Translate(Vector3.forward * Time.deltaTime * _Speed);
|
||||
}
|
||||
|
||||
if (_Car.transform.position.x >= _Points[1].transform.position.x && _LeftToRight)
|
||||
{
|
||||
DeleteCar();
|
||||
}
|
||||
else if (_Car.transform.position.x <= _Points[0].transform.position.x && !_LeftToRight)
|
||||
{
|
||||
DeleteCar();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,21 +73,29 @@ public class CarManagerScript : MonoBehaviour
|
||||
{
|
||||
Vector3 pos;
|
||||
Quaternion rot;
|
||||
|
||||
// разница до колеса
|
||||
|
||||
if (_LeftToRight)
|
||||
{
|
||||
pos = _Points[0].transform.position;
|
||||
pos = new Vector3(_Points[0].transform.position.x, _Points[0].transform.position.y, _Points[0].transform.position.z);
|
||||
rot = Quaternion.Euler(0, 90, 0);
|
||||
|
||||
_Car = Instantiate(GetRandomObject<GameObject>(_CarPrefs), pos, rot);
|
||||
}
|
||||
else if (!_LeftToRight)
|
||||
{
|
||||
pos = _Points[1].transform.position;
|
||||
pos = new Vector3(_Points[1].transform.position.x, _Points[1].transform.position.y, _Points[1].transform.position.z);
|
||||
rot = Quaternion.Euler(0, -90, 0);
|
||||
|
||||
_Car = Instantiate(GetRandomObject<GameObject>(_CarPrefs), pos, rot);
|
||||
}
|
||||
//_Car.transform.SetParent(gameObject.transform, _Points[1].transform);
|
||||
|
||||
float high = _Car.GetComponent<CarControllerScript>().High;
|
||||
|
||||
_Car.transform.position = pos = new Vector3(_Car.transform.position.x, _Car.transform.position.y + high, _Car.transform.position.z);
|
||||
|
||||
_Car.transform.SetParent(gameObject.transform);
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user