SanAndreasUnity/Assets/Scripts/Behaviours/UIVehicleSpawner.cs

62 lines
1.5 KiB
C#
Raw Normal View History

2020-05-31 17:07:22 +00:00
using SanAndreasUnity.Behaviours;
using UnityEngine;
2019-07-05 22:55:42 +00:00
namespace SanAndreasUnity.Behaviours
2020-05-31 17:07:22 +00:00
{
2019-07-05 22:55:42 +00:00
public class UIVehicleSpawner : MonoBehaviour
2020-05-31 17:07:22 +00:00
{
2019-07-05 22:55:42 +00:00
public Vector3 spawnOffset = new Vector3(0, 2, 5);
public KeyCode spawnKey = KeyCode.V;
2020-05-31 17:07:22 +00:00
2019-07-05 22:55:42 +00:00
private void Start()
2020-05-31 17:07:22 +00:00
{
2019-07-05 22:55:42 +00:00
2020-05-31 17:07:22 +00:00
}
2019-07-05 22:55:42 +00:00
private void Update()
{
if (Input.GetKeyDown(spawnKey))
{
if (Utilities.NetUtils.IsServer)
SpawnVehicle();
else if (Net.PlayerRequests.Local != null)
Net.PlayerRequests.Local.RequestVehicleSpawn();
}
}
2020-05-31 17:07:22 +00:00
2019-07-05 22:55:42 +00:00
public void SpawnVehicle()
{
var ped = Ped.Instance;
2020-05-31 17:07:22 +00:00
2019-07-05 22:55:42 +00:00
if (null == ped)
return;
SpawnVehicle(ped);
}
2019-07-05 21:46:59 +00:00
2019-07-05 22:55:42 +00:00
public void SpawnVehicle(Ped ped)
{
Vector3 pos = ped.transform.position + ped.transform.forward * spawnOffset.z + ped.transform.up * spawnOffset.y
+ ped.transform.right * spawnOffset.x;
Quaternion rotation = Quaternion.LookRotation(-ped.transform.right, Vector3.up);
2019-07-05 21:46:59 +00:00
2019-07-05 22:55:42 +00:00
SpawnVehicle(pos, rotation);
}
public void SpawnVehicle(Vector3 pos, Quaternion rotation)
{
// SanAndreasUnity.Behaviours.Vehicles.VehicleSpawner.Create ();
var v = SanAndreasUnity.Behaviours.Vehicles.Vehicle.Create(-1, null, pos, rotation);
Debug.Log("Spawned vehicle with id " + v.Definition.Id);
}
2019-07-05 21:46:59 +00:00
}
2019-07-05 22:55:42 +00:00
}