Hässliche reuden ranz Map-Begrenzung
This commit is contained in:
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ec3ddfd42ea73d4f92b48f1b1142b81
|
||||
folderAsset: yes
|
||||
timeCreated: 1570639189
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,31 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class LPPV_CarRotation : MonoBehaviour {
|
||||
|
||||
private float targetAngle;
|
||||
private float vel;
|
||||
private float smoothSpeed = 10f;
|
||||
|
||||
private void Start ()
|
||||
{
|
||||
if (transform.localEulerAngles.y > 0)
|
||||
{
|
||||
targetAngle = 25f + transform.localEulerAngles.y;
|
||||
}else
|
||||
{
|
||||
targetAngle = -25f - transform.localEulerAngles.y;
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate ()
|
||||
{
|
||||
Quaternion target = Quaternion.Euler (new Vector3(transform.localEulerAngles.x, targetAngle, transform.localEulerAngles.z));
|
||||
transform.rotation = Quaternion.Slerp (transform.rotation, target, Time.deltaTime * smoothSpeed);
|
||||
if (targetAngle > 0)
|
||||
targetAngle++;
|
||||
else
|
||||
targetAngle--;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4d17ceb8f8c81d64a8468c596b7c2195
|
||||
timeCreated: 1570641701
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,67 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class LPPV_CarSelection : MonoBehaviour {
|
||||
|
||||
public static CarType currentCarType;
|
||||
|
||||
[SerializeField] private GameObject nextButton, prevButton;
|
||||
[SerializeField] private Camera cam;
|
||||
private int currentCar = 0;
|
||||
|
||||
public enum CarType
|
||||
{
|
||||
Sedan, Sports, Utility, Bus
|
||||
}
|
||||
|
||||
private void CheckStatus()
|
||||
{
|
||||
currentCar = Mathf.Clamp (currentCar, 0, 3);
|
||||
if (nextButton == null || prevButton == null)
|
||||
return;
|
||||
|
||||
if (currentCar <= 0)
|
||||
{
|
||||
prevButton.SetActive (false);
|
||||
nextButton.SetActive (true);
|
||||
} else if (currentCar >= 3)
|
||||
{
|
||||
prevButton.SetActive (true);
|
||||
nextButton.SetActive (false);
|
||||
} else
|
||||
{
|
||||
prevButton.SetActive (true);
|
||||
nextButton.SetActive (true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (nextButton != null)
|
||||
{
|
||||
if(nextButton.GetComponent<Button>())
|
||||
nextButton.GetComponent<Button> ().onClick.AddListener (() => { currentCar++; if(cam != null) cam.transform.position = new Vector3(cam.transform.position.x + 20f, cam.transform.position.y, cam.transform.position.z);} );
|
||||
}
|
||||
if (prevButton != null)
|
||||
{
|
||||
if(prevButton.GetComponent<Button>())
|
||||
prevButton.GetComponent<Button> ().onClick.AddListener (() => { currentCar--; if(cam != null) cam.transform.position = new Vector3(cam.transform.position.x - 20f, cam.transform.position.y, cam.transform.position.z); } );
|
||||
}
|
||||
CheckStatus ();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
CheckStatus ();
|
||||
}
|
||||
|
||||
public void SelectCar()
|
||||
{
|
||||
currentCarType = (CarType)currentCar;
|
||||
SceneManager.LoadScene (1);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de0dfc9e6302f1f4c867a6d17cbed27d
|
||||
timeCreated: 1570639421
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,31 @@
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine;
|
||||
|
||||
public class LPPV_GameManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject sedan, sports, utility, bus;
|
||||
private void Start()
|
||||
{
|
||||
if (sedan == null || sports == null || utility == null || bus == null)
|
||||
return;
|
||||
|
||||
sedan.SetActive (false);
|
||||
sports.SetActive(false);
|
||||
utility.SetActive(false);
|
||||
bus.SetActive(false);
|
||||
|
||||
if (LPPV_CarSelection.currentCarType == LPPV_CarSelection.CarType.Sedan)
|
||||
sedan.SetActive (true);
|
||||
else if (LPPV_CarSelection.currentCarType == LPPV_CarSelection.CarType.Sports)
|
||||
sports.SetActive (true);
|
||||
else if (LPPV_CarSelection.currentCarType == LPPV_CarSelection.CarType.Utility)
|
||||
utility.SetActive (true);
|
||||
else if (LPPV_CarSelection.currentCarType == LPPV_CarSelection.CarType.Bus)
|
||||
bus.SetActive (true);
|
||||
}
|
||||
|
||||
public void LoadLevel(int index)
|
||||
{
|
||||
SceneManager.LoadScene (index);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57e1997ac57318c488fc7c9da8832a93
|
||||
timeCreated: 1570645236
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,29 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(MeshRenderer))]
|
||||
public class LPPV_BrakeLight : MonoBehaviour {
|
||||
|
||||
private MeshRenderer _mr;
|
||||
private LPPV_CarController _cc;
|
||||
// Use this for initialization
|
||||
void Start ()
|
||||
{
|
||||
_mr = GetComponent<MeshRenderer> ();
|
||||
_mr.enabled = false;
|
||||
_cc = GameObject.FindObjectOfType<LPPV_CarController> ();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update ()
|
||||
{
|
||||
if (_cc != null)
|
||||
{
|
||||
if (_cc.Deccelerating || _cc.HandBrake)
|
||||
_mr.enabled = true;
|
||||
else
|
||||
_mr.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2900242f864e8849ace533ce977dec3
|
||||
timeCreated: 1570644824
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,202 @@
|
||||
/*
|
||||
* This Script Controls the car!
|
||||
*/
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class LPPV_CarController : MonoBehaviour {
|
||||
|
||||
|
||||
public enum WheelType
|
||||
{
|
||||
FrontLeft, FrontRight, RearLeft, RearRight
|
||||
}
|
||||
public enum SpeedUnit
|
||||
{
|
||||
Imperial, Metric
|
||||
}
|
||||
[Serializable]
|
||||
class Wheel
|
||||
{
|
||||
public WheelCollider collider;
|
||||
public GameObject mesh;
|
||||
public WheelType wheelType;
|
||||
}
|
||||
|
||||
[SerializeField] private Wheel[] wheels = new Wheel[4];
|
||||
[SerializeField] private float maxTorque = 2000f, maxBrakeTorque = 500f, maxSteerAngle = 30f; //max Torque of Wheels, max Brake Torque and Maximum Steer Angle of steerable wheels
|
||||
[SerializeField] private static int NoOfGears = 5;
|
||||
[SerializeField] private float downForce = 100f; // The Force to apply downwards so that car stays on track!
|
||||
[SerializeField] private SpeedUnit speedUnit; //Speed Unit - Imperial - Miles Per Hour, Metric - Kilometers Per Hour
|
||||
[SerializeField] private float topSpeed = 140;
|
||||
[SerializeField] private Transform centerOfMass;
|
||||
[SerializeField] private Text speedText;
|
||||
|
||||
#if UNITY_ANDROID || UNITY_IOS
|
||||
[SerializeField] private LPPV_VButton accelerateButton, brakeButton, handBrakeButton;
|
||||
#endif
|
||||
|
||||
[HideInInspector] public bool Accelerating = false, Deccelerating = false, HandBrake = false;
|
||||
private Rigidbody _rgbd;
|
||||
public float CurrentSpeed{
|
||||
get
|
||||
{
|
||||
float speed = _rgbd.velocity.magnitude;
|
||||
if (speedUnit == SpeedUnit.Imperial)
|
||||
speed *= 2.23693629f;
|
||||
else
|
||||
speed *= 3.6f;
|
||||
return speed;
|
||||
}
|
||||
}
|
||||
|
||||
private void VisualizeWheel(Wheel wheel)
|
||||
{
|
||||
//This method copies the position and rotation of the wheel collider and pastes it to the corresponding mesh!
|
||||
if (wheel.mesh == null || wheel.collider == null)
|
||||
return;
|
||||
|
||||
Vector3 position;
|
||||
Quaternion rotation;
|
||||
wheel.collider.GetWorldPose(out position, out rotation); //Fetch the position and Rotation from the WheelCollider into temporary variables
|
||||
|
||||
wheel.mesh.transform.position = position;
|
||||
wheel.mesh.transform.rotation = rotation;
|
||||
}
|
||||
|
||||
private void Start ()
|
||||
{
|
||||
_rgbd = GetComponent<Rigidbody> ();
|
||||
if (centerOfMass != null && _rgbd != null)
|
||||
_rgbd.centerOfMass = centerOfMass.localPosition;
|
||||
for (int i = 0; i < wheels.Length; ++i)
|
||||
VisualizeWheel (wheels [i]);
|
||||
}
|
||||
|
||||
private void Move(float motorInput, float steerInput, bool handBrake)
|
||||
{
|
||||
HandBrake = handBrake;
|
||||
motorInput = Mathf.Clamp (motorInput, -1f, 1f);
|
||||
if (motorInput > 0f)
|
||||
{
|
||||
//Accelerate vehicle!
|
||||
Accelerating = true;
|
||||
Deccelerating = false;
|
||||
} else if(motorInput < 0f)
|
||||
{
|
||||
//Brake Vehicle!
|
||||
Accelerating = false;
|
||||
Deccelerating = true;
|
||||
}
|
||||
|
||||
steerInput = Mathf.Clamp (steerInput, -1f, 1f);
|
||||
float steer = steerInput * maxSteerAngle;
|
||||
|
||||
for (int i = 0; i < wheels.Length; ++i)
|
||||
{
|
||||
if (wheels [i].collider == null)
|
||||
break;
|
||||
if (wheels [i].wheelType == WheelType.FrontLeft || wheels [i].wheelType == WheelType.FrontRight)
|
||||
{
|
||||
wheels [i].collider.steerAngle = steer;
|
||||
|
||||
}
|
||||
if (!handBrake)
|
||||
{
|
||||
wheels [i].collider.brakeTorque = 0f;
|
||||
if (Accelerating)
|
||||
wheels [i].collider.motorTorque = motorInput * maxTorque / 4f;
|
||||
else if (Deccelerating)
|
||||
wheels [i].collider.motorTorque = motorInput * maxBrakeTorque / 4f;
|
||||
} else
|
||||
{
|
||||
if (wheels [i].wheelType == WheelType.RearLeft || wheels [i].wheelType == WheelType.RearRight)
|
||||
wheels [i].collider.brakeTorque = maxBrakeTorque * 20f;
|
||||
wheels [i].collider.motorTorque = 0f;
|
||||
}
|
||||
if(wheels[i].mesh != null)
|
||||
VisualizeWheel (wheels [i]);
|
||||
}
|
||||
|
||||
StickToTheGround ();
|
||||
ManageSpeed ();
|
||||
}
|
||||
|
||||
//This Method Applies down force so that car grips the ground strongly
|
||||
private void StickToTheGround()
|
||||
{
|
||||
if (wheels [0].collider == null)
|
||||
return;
|
||||
wheels [0].collider.attachedRigidbody.AddForce (-transform.up * downForce * wheels [0].collider.attachedRigidbody.velocity.magnitude);
|
||||
}
|
||||
|
||||
|
||||
//used to keep speed withing Minimum and maximum Speed Limits
|
||||
private void ManageSpeed()
|
||||
{
|
||||
float speed = _rgbd.velocity.magnitude;
|
||||
switch (speedUnit)
|
||||
{
|
||||
case SpeedUnit.Imperial:
|
||||
speed *= 2.23693629f;
|
||||
if (speed > topSpeed)
|
||||
_rgbd.velocity = (topSpeed/2.23693629f) * _rgbd.velocity.normalized;
|
||||
break;
|
||||
|
||||
case SpeedUnit.Metric:
|
||||
speed *= 3.6f;
|
||||
if (speed > topSpeed)
|
||||
_rgbd.velocity = (topSpeed/3.6f) * _rgbd.velocity.normalized;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private string imp = " MPH", met = " KPH";
|
||||
private void Update()
|
||||
{
|
||||
if (speedText != null)
|
||||
{
|
||||
if(speedUnit == SpeedUnit.Imperial)
|
||||
speedText.text = ((int)CurrentSpeed).ToString () + imp;
|
||||
else
|
||||
speedText.text = ((int)CurrentSpeed).ToString () + met;
|
||||
}
|
||||
}
|
||||
private void FixedUpdate()
|
||||
{
|
||||
float motor = 0f, steering = 0f;
|
||||
bool handBrakeInput = false;
|
||||
#if UNITY_STANDALONE || UNITY_WEBGL
|
||||
motor = Input.GetAxis("Vertical");
|
||||
steering = Input.GetAxis("Horizontal");
|
||||
handBrakeInput = Input.GetButton ("Jump");
|
||||
#endif
|
||||
|
||||
#if UNITY_ANDROID || UNITY_IOS
|
||||
steering = Input.acceleration.x;
|
||||
if(accelerateButton != null)
|
||||
{
|
||||
if(accelerateButton.value)
|
||||
motor = 1f;
|
||||
}
|
||||
if(brakeButton != null)
|
||||
{
|
||||
if(brakeButton.value)
|
||||
motor = -1f;
|
||||
}
|
||||
if(handBrakeButton != null)
|
||||
{
|
||||
handBrakeInput = handBrakeButton.value;
|
||||
if(handBrakeButton.value)
|
||||
{
|
||||
motor = 0f;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Move (motor, steering, handBrakeInput);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 87bb700abfc93c64c8d364fd654e4a06
|
||||
timeCreated: 1570615899
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,31 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class LPPV_Follow : MonoBehaviour {
|
||||
|
||||
[SerializeField] private Transform target;
|
||||
[SerializeField] private float rotationDamping = 10f;
|
||||
[SerializeField] private float distance = 3.0f;
|
||||
[SerializeField] private float height = 3.0f;
|
||||
[SerializeField] private float damping = 5.0f;
|
||||
[SerializeField] private bool smoothRotation = true;
|
||||
[SerializeField] private bool followBehind = true;
|
||||
|
||||
void FixedUpdate ()
|
||||
{
|
||||
Vector3 wantedPosition;
|
||||
if(followBehind)
|
||||
wantedPosition = target.TransformPoint(0, height, -distance);
|
||||
else
|
||||
wantedPosition = target.TransformPoint(0, height, distance);
|
||||
|
||||
transform.position = Vector3.Lerp (transform.position, wantedPosition, Time.deltaTime * damping);
|
||||
|
||||
if (smoothRotation) {
|
||||
Quaternion wantedRotation = Quaternion.LookRotation(target.position - transform.position, target.up);
|
||||
transform.rotation = Quaternion.Slerp (transform.rotation, wantedRotation, Time.deltaTime * rotationDamping);
|
||||
}
|
||||
else transform.LookAt (target, target.up);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c44fbf2dc430fc444be7c2196e0c3851
|
||||
timeCreated: 1570620168
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,65 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class LPPV_VButton : MonoBehaviour {
|
||||
|
||||
public enum ButtonType
|
||||
{
|
||||
TriggerButton, HoldButton
|
||||
}
|
||||
|
||||
public ButtonType buttonType;
|
||||
|
||||
[HideInInspector]
|
||||
public bool value;
|
||||
|
||||
private EventTrigger _eventTrigger;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
SetEventTrigger ();
|
||||
}
|
||||
|
||||
private void SetEventTrigger()
|
||||
{
|
||||
if (GetComponent<EventTrigger> ()) {
|
||||
_eventTrigger = GetComponent<EventTrigger> ();
|
||||
} else {
|
||||
gameObject.AddComponent<EventTrigger> ();
|
||||
_eventTrigger = GetComponent<EventTrigger> ();
|
||||
}
|
||||
|
||||
EventTrigger.Entry entry = new EventTrigger.Entry();
|
||||
entry.eventID = EventTriggerType.PointerDown;
|
||||
entry.callback.AddListener((eventData) => {OnButtonDown();});
|
||||
_eventTrigger.triggers = new List<EventTrigger.Entry> ();
|
||||
_eventTrigger.triggers.Add(entry);
|
||||
|
||||
|
||||
EventTrigger.Entry entry1 = new EventTrigger.Entry();
|
||||
entry1.eventID = EventTriggerType.PointerUp;
|
||||
entry1.callback.AddListener((eventData) => {OnButtonUp();});
|
||||
_eventTrigger.triggers.Add(entry1);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (buttonType == ButtonType.TriggerButton)
|
||||
{
|
||||
if (value)
|
||||
value = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnButtonDown()
|
||||
{
|
||||
value = true;
|
||||
}
|
||||
|
||||
public void OnButtonUp()
|
||||
{
|
||||
value = false;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: af4b9e1e3f365c74ba171956479ecc74
|
||||
timeCreated: 1570699682
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user