Player, player movement, camera control
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BuildManager : MonoBehaviour
|
||||
{
|
||||
public GameObject WebGLCanvas;
|
||||
public GameObject WarningPanel;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
#if UNITY_WEBGL && !UNITY_EDITOR
|
||||
WebGLCanvas.SetActive(true);
|
||||
#endif
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if(Input.GetKeyDown(KeyCode.F1))
|
||||
{
|
||||
UnityEngine.SceneManagement.SceneManager.LoadScene(0);
|
||||
}
|
||||
|
||||
#if UNITY_WEBGL && !UNITY_EDITOR
|
||||
if(Input.GetKeyDown(KeyCode.H))
|
||||
{
|
||||
WarningPanel.SetActive(!WarningPanel.activeSelf);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f83a0772ca2f284c97e6c2e3b8b6c5b
|
||||
timeCreated: 1506813597
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a33f03bd56f612745924ea5d3583c912
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using KinematicCharacterController;
|
||||
|
||||
public class PauseStateHandler
|
||||
{
|
||||
[RuntimeInitializeOnLoadMethod()]
|
||||
public static void Init()
|
||||
{
|
||||
EditorApplication.pauseStateChanged += HandlePauseStateChange;
|
||||
}
|
||||
|
||||
private static void HandlePauseStateChange(PauseState state)
|
||||
{
|
||||
foreach(KinematicCharacterMotor motor in KinematicCharacterSystem.CharacterMotors)
|
||||
{
|
||||
motor.SetPositionAndRotation(motor.Transform.position, motor.Transform.rotation, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 23fa5eb46266f154aa2d50e3538b4eca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace KinematicCharacterController.Examples
|
||||
{
|
||||
public class ExampleAIController : MonoBehaviour
|
||||
{
|
||||
public float MovementPeriod = 1f;
|
||||
public List<ExampleCharacterController> Characters = new List<ExampleCharacterController>();
|
||||
|
||||
private bool _stepHandling;
|
||||
private bool _ledgeHandling;
|
||||
private bool _intHandling;
|
||||
private bool _safeMove;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
AICharacterInputs inputs = new AICharacterInputs();
|
||||
|
||||
// Simulate an input on all controlled characters
|
||||
inputs.MoveVector = Mathf.Sin(Time.time * MovementPeriod) * Vector3.forward;
|
||||
inputs.LookVector = Vector3.Slerp(-Vector3.forward, Vector3.forward, inputs.MoveVector.z).normalized;
|
||||
for (int i = 0; i < Characters.Count; i++)
|
||||
{
|
||||
Characters[i].SetInputs(ref inputs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f3414c4d01b68ef43aa3339915fd4001
|
||||
timeCreated: 1504385569
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,39 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace KinematicCharacterController.Examples
|
||||
{
|
||||
public class ExampleMovingPlatform : MonoBehaviour, IMoverController
|
||||
{
|
||||
public PhysicsMover Mover;
|
||||
|
||||
public Vector3 TranslationAxis = Vector3.right;
|
||||
public float TranslationPeriod = 10;
|
||||
public float TranslationSpeed = 1;
|
||||
public Vector3 RotationAxis = Vector3.up;
|
||||
public float RotSpeed = 10;
|
||||
public Vector3 OscillationAxis = Vector3.zero;
|
||||
public float OscillationPeriod = 10;
|
||||
public float OscillationSpeed = 10;
|
||||
|
||||
private Vector3 _originalPosition;
|
||||
private Quaternion _originalRotation;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_originalPosition = Mover.Rigidbody.position;
|
||||
_originalRotation = Mover.Rigidbody.rotation;
|
||||
|
||||
Mover.MoverController = this;
|
||||
}
|
||||
|
||||
public void UpdateMovement(out Vector3 goalPosition, out Quaternion goalRotation, float deltaTime)
|
||||
{
|
||||
goalPosition = (_originalPosition + (TranslationAxis.normalized * Mathf.Sin(Time.time * TranslationSpeed) * TranslationPeriod));
|
||||
|
||||
Quaternion targetRotForOscillation = Quaternion.Euler(OscillationAxis.normalized * (Mathf.Sin(Time.time * OscillationSpeed) * OscillationPeriod)) * _originalRotation;
|
||||
goalRotation = Quaternion.Euler(RotationAxis * RotSpeed * Time.time) * targetRotForOscillation;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b7edc6957dab9ac4797c1c0912ce3839
|
||||
timeCreated: 1496714854
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,153 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace KinematicCharacterController.Examples
|
||||
{
|
||||
public class FrameratePanel : MonoBehaviour
|
||||
{
|
||||
public float PollingRate = 1f;
|
||||
public Text PhysicsRate;
|
||||
public Text PhysicsFPS;
|
||||
public Text AvgFPS;
|
||||
public Text AvgFPSMin;
|
||||
public Text AvgFPSMax;
|
||||
|
||||
public Action<float> OnPhysicsFPSReady;
|
||||
|
||||
public string[] FramerateStrings = new string[0];
|
||||
|
||||
private bool _isFixedUpdateThisFrame = false;
|
||||
private bool _wasFixedUpdateLastFrame = false;
|
||||
private int _physFramesCount = 0;
|
||||
private float _physFramesDeltaSum = 0;
|
||||
|
||||
private int _framesCount = 0;
|
||||
private float _framesDeltaSum = 0;
|
||||
private float _minDeltaTimeForAvg = Mathf.Infinity;
|
||||
private float _maxDeltaTimeForAvg = Mathf.NegativeInfinity;
|
||||
private float _timeOfLastPoll = 0;
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
_isFixedUpdateThisFrame = true;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// Regular frames
|
||||
_framesCount++;
|
||||
_framesDeltaSum += Time.deltaTime;
|
||||
|
||||
// Max and min
|
||||
if (Time.deltaTime < _minDeltaTimeForAvg)
|
||||
{
|
||||
_minDeltaTimeForAvg = Time.deltaTime;
|
||||
}
|
||||
if (Time.deltaTime > _maxDeltaTimeForAvg)
|
||||
{
|
||||
_maxDeltaTimeForAvg = Time.deltaTime;
|
||||
}
|
||||
|
||||
// Fixed frames
|
||||
if (_wasFixedUpdateLastFrame)
|
||||
{
|
||||
_wasFixedUpdateLastFrame = false;
|
||||
|
||||
_physFramesCount++;
|
||||
_physFramesDeltaSum += Time.deltaTime;
|
||||
}
|
||||
if (_isFixedUpdateThisFrame)
|
||||
{
|
||||
_wasFixedUpdateLastFrame = true;
|
||||
_isFixedUpdateThisFrame = false;
|
||||
}
|
||||
|
||||
// Polling timer
|
||||
float timeSinceLastPoll = (Time.unscaledTime - _timeOfLastPoll);
|
||||
if (timeSinceLastPoll > PollingRate)
|
||||
{
|
||||
float physicsFPS = 1f / (_physFramesDeltaSum / _physFramesCount);
|
||||
|
||||
AvgFPS.text = GetNumberString(Mathf.RoundToInt(1f / (_framesDeltaSum / _framesCount)));
|
||||
AvgFPSMin.text = GetNumberString(Mathf.RoundToInt(1f / _maxDeltaTimeForAvg));
|
||||
AvgFPSMax.text = GetNumberString(Mathf.RoundToInt(1f / _minDeltaTimeForAvg));
|
||||
PhysicsFPS.text = GetNumberString(Mathf.RoundToInt(physicsFPS));
|
||||
|
||||
if(OnPhysicsFPSReady != null)
|
||||
{
|
||||
OnPhysicsFPSReady(physicsFPS);
|
||||
}
|
||||
|
||||
_physFramesDeltaSum = 0;
|
||||
_physFramesCount = 0;
|
||||
_framesDeltaSum = 0f;
|
||||
_framesCount = 0;
|
||||
_minDeltaTimeForAvg = Mathf.Infinity;
|
||||
_maxDeltaTimeForAvg = Mathf.NegativeInfinity;
|
||||
|
||||
_timeOfLastPoll = Time.unscaledTime;
|
||||
}
|
||||
|
||||
PhysicsRate.text = GetNumberString(Mathf.RoundToInt(1f / Time.fixedDeltaTime));
|
||||
}
|
||||
|
||||
public string GetNumberString(int fps)
|
||||
{
|
||||
if (fps < FramerateStrings.Length - 1 && fps >= 0)
|
||||
{
|
||||
return FramerateStrings[fps];
|
||||
}
|
||||
else
|
||||
{
|
||||
return FramerateStrings[FramerateStrings.Length - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[CustomEditor(typeof(FrameratePanel))]
|
||||
public class FrameratePanelEditor : Editor
|
||||
{
|
||||
private const int MaxFPS = 999;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
InitStringsArray();
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
DrawDefaultInspector();
|
||||
|
||||
if (GUILayout.Button("Init strings array"))
|
||||
{
|
||||
InitStringsArray();
|
||||
}
|
||||
}
|
||||
|
||||
private void InitStringsArray()
|
||||
{
|
||||
FrameratePanel fp = target as FrameratePanel;
|
||||
fp.FramerateStrings = new string[MaxFPS + 1];
|
||||
|
||||
for (int i = 0; i < fp.FramerateStrings.Length; i++)
|
||||
{
|
||||
if (i >= fp.FramerateStrings.Length - 1)
|
||||
{
|
||||
fp.FramerateStrings[i] = i.ToString() + "+" + " (<" + (1000f / (float)i).ToString("F") + "ms)";
|
||||
}
|
||||
else
|
||||
{
|
||||
fp.FramerateStrings[i] = i.ToString() + " (" + (1000f/(float)i).ToString("F") + "ms)" ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e404bfefdeb79904e847365ad9c6c205
|
||||
timeCreated: 1501357153
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,66 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using KinematicCharacterController;
|
||||
using KinematicCharacterController.Examples;
|
||||
using System;
|
||||
|
||||
namespace KinematicCharacterController.Examples
|
||||
{
|
||||
public class PlanetManager : MonoBehaviour, IMoverController
|
||||
{
|
||||
public PhysicsMover PlanetMover;
|
||||
public SphereCollider GravityField;
|
||||
public float GravityStrength = 10;
|
||||
public Vector3 OrbitAxis = Vector3.forward;
|
||||
public float OrbitSpeed = 10;
|
||||
|
||||
public Teleporter OnPlaygroundTeleportingZone;
|
||||
public Teleporter OnPlanetTeleportingZone;
|
||||
|
||||
private List<ExampleCharacterController> _characterControllersOnPlanet = new List<ExampleCharacterController>();
|
||||
private Vector3 _savedGravity;
|
||||
private Quaternion _lastRotation;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
OnPlaygroundTeleportingZone.OnCharacterTeleport -= ControlGravity;
|
||||
OnPlaygroundTeleportingZone.OnCharacterTeleport += ControlGravity;
|
||||
|
||||
OnPlanetTeleportingZone.OnCharacterTeleport -= UnControlGravity;
|
||||
OnPlanetTeleportingZone.OnCharacterTeleport += UnControlGravity;
|
||||
|
||||
_lastRotation = PlanetMover.transform.rotation;
|
||||
|
||||
PlanetMover.MoverController = this;
|
||||
}
|
||||
|
||||
public void UpdateMovement(out Vector3 goalPosition, out Quaternion goalRotation, float deltaTime)
|
||||
{
|
||||
goalPosition = PlanetMover.Rigidbody.position;
|
||||
|
||||
// Rotate
|
||||
Quaternion targetRotation = Quaternion.Euler(OrbitAxis * OrbitSpeed * deltaTime) * _lastRotation;
|
||||
goalRotation = targetRotation;
|
||||
_lastRotation = targetRotation;
|
||||
|
||||
// Apply gravity to characters
|
||||
foreach (ExampleCharacterController cc in _characterControllersOnPlanet)
|
||||
{
|
||||
cc.Gravity = (PlanetMover.transform.position - cc.transform.position).normalized * GravityStrength;
|
||||
}
|
||||
}
|
||||
|
||||
void ControlGravity(ExampleCharacterController cc)
|
||||
{
|
||||
_savedGravity = cc.Gravity;
|
||||
_characterControllersOnPlanet.Add(cc);
|
||||
}
|
||||
|
||||
void UnControlGravity(ExampleCharacterController cc)
|
||||
{
|
||||
cc.Gravity = _savedGravity;
|
||||
_characterControllersOnPlanet.Remove(cc);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e89f443ce54ba1e469d5dd7141034d04
|
||||
timeCreated: 1499314453
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,53 @@
|
||||
using KinematicCharacterController;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using UnityEngine.Playables;
|
||||
|
||||
namespace KinematicCharacterController.Examples
|
||||
{
|
||||
public class PlayableMover : MonoBehaviour, IMoverController
|
||||
{
|
||||
public PhysicsMover Mover;
|
||||
|
||||
public float Speed = 1f;
|
||||
public PlayableDirector Director;
|
||||
|
||||
private Transform _transform;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_transform = this.transform;
|
||||
Director.timeUpdateMode = DirectorUpdateMode.Manual;
|
||||
|
||||
Mover.MoverController = this;
|
||||
}
|
||||
|
||||
// This is called every FixedUpdate by our PhysicsMover in order to tell it what pose it should go to
|
||||
public void UpdateMovement(out Vector3 goalPosition, out Quaternion goalRotation, float deltaTime)
|
||||
{
|
||||
// Remember pose before animation
|
||||
Vector3 _positionBeforeAnim = _transform.position;
|
||||
Quaternion _rotationBeforeAnim = _transform.rotation;
|
||||
|
||||
// Update animation
|
||||
EvaluateAtTime(Time.time * Speed);
|
||||
|
||||
// Set our platform's goal pose to the animation's
|
||||
goalPosition = _transform.position;
|
||||
goalRotation = _transform.rotation;
|
||||
|
||||
// Reset the actual transform pose to where it was before evaluating.
|
||||
// This is so that the real movement can be handled by the physics mover; not the animation
|
||||
_transform.position = _positionBeforeAnim;
|
||||
_transform.rotation = _rotationBeforeAnim;
|
||||
}
|
||||
|
||||
public void EvaluateAtTime(double time)
|
||||
{
|
||||
Director.time = time % Director.duration;
|
||||
Director.Evaluate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 160d994062e8fe6418c50c339a9e34e0
|
||||
timeCreated: 1523122627
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace KinematicCharacterController.Examples
|
||||
{
|
||||
public class PrefabLauncher : MonoBehaviour
|
||||
{
|
||||
public Rigidbody ToLaunch;
|
||||
public float Force;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Return))
|
||||
{
|
||||
Rigidbody inst = Instantiate(ToLaunch, transform.position, transform.rotation);
|
||||
inst.AddForce(transform.forward * Force, ForceMode.VelocityChange);
|
||||
Destroy(inst.gameObject, 8f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a743ceeddb93f0e4981433a18d793f00
|
||||
timeCreated: 1487896989
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,103 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace KinematicCharacterController.Examples
|
||||
{
|
||||
public class StressTestManager : MonoBehaviour
|
||||
{
|
||||
public Camera Camera;
|
||||
public LayerMask UIMask;
|
||||
|
||||
public InputField CountField;
|
||||
public Image RenderOn;
|
||||
public Image SimOn;
|
||||
public Image InterpOn;
|
||||
public ExampleCharacterController CharacterPrefab;
|
||||
public ExampleAIController AIController;
|
||||
public int SpawnCount = 100;
|
||||
public float SpawnDistance = 2f;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
KinematicCharacterSystem.EnsureCreation();
|
||||
CountField.text = SpawnCount.ToString();
|
||||
UpdateOnImages();
|
||||
|
||||
KinematicCharacterSystem.Settings.AutoSimulation = false;
|
||||
KinematicCharacterSystem.Settings.Interpolate = false;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
|
||||
KinematicCharacterSystem.Simulate(Time.deltaTime, KinematicCharacterSystem.CharacterMotors, KinematicCharacterSystem.PhysicsMovers);
|
||||
}
|
||||
|
||||
private void UpdateOnImages()
|
||||
{
|
||||
RenderOn.enabled = Camera.cullingMask == -1;
|
||||
SimOn.enabled = Physics.autoSimulation;
|
||||
InterpOn.enabled = KinematicCharacterSystem.Settings.Interpolate;
|
||||
}
|
||||
|
||||
public void SetSpawnCount(string count)
|
||||
{
|
||||
if (int.TryParse(count, out int result))
|
||||
{
|
||||
SpawnCount = result;
|
||||
}
|
||||
}
|
||||
|
||||
public void ToggleRendering()
|
||||
{
|
||||
if(Camera.cullingMask == -1)
|
||||
{
|
||||
Camera.cullingMask = UIMask;
|
||||
}
|
||||
else
|
||||
{
|
||||
Camera.cullingMask = -1;
|
||||
}
|
||||
UpdateOnImages();
|
||||
}
|
||||
|
||||
public void TogglePhysicsSim()
|
||||
{
|
||||
Physics.autoSimulation = !Physics.autoSimulation;
|
||||
UpdateOnImages();
|
||||
}
|
||||
|
||||
public void ToggleInterpolation()
|
||||
{
|
||||
KinematicCharacterSystem.Settings.Interpolate = !KinematicCharacterSystem.Settings.Interpolate;
|
||||
UpdateOnImages();
|
||||
}
|
||||
|
||||
public void Spawn()
|
||||
{
|
||||
for (int i = 0; i < AIController.Characters.Count; i++)
|
||||
{
|
||||
Destroy(AIController.Characters[i].gameObject);
|
||||
}
|
||||
AIController.Characters.Clear();
|
||||
|
||||
int charsPerRow = Mathf.CeilToInt(Mathf.Sqrt(SpawnCount));
|
||||
Vector3 firstPos = ((charsPerRow * SpawnDistance) * 0.5f) * -Vector3.one;
|
||||
firstPos.y = 0f;
|
||||
|
||||
for (int i = 0; i < SpawnCount; i++)
|
||||
{
|
||||
int row = i / charsPerRow;
|
||||
int col = i % charsPerRow;
|
||||
Vector3 pos = firstPos + (Vector3.right * row * SpawnDistance) + (Vector3.forward * col * SpawnDistance);
|
||||
|
||||
ExampleCharacterController newChar = Instantiate(CharacterPrefab);
|
||||
newChar.Motor.SetPosition(pos);
|
||||
|
||||
AIController.Characters.Add(newChar);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d701116f722c264688042f476bbb604
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using KinematicCharacterController.Examples;
|
||||
|
||||
namespace KinematicCharacterController.Examples
|
||||
{
|
||||
public class Teleporter : MonoBehaviour
|
||||
{
|
||||
public Teleporter TeleportTo;
|
||||
|
||||
public UnityAction<ExampleCharacterController> OnCharacterTeleport;
|
||||
|
||||
public bool isBeingTeleportedTo { get; set; }
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (!isBeingTeleportedTo)
|
||||
{
|
||||
ExampleCharacterController cc = other.GetComponent<ExampleCharacterController>();
|
||||
if (cc)
|
||||
{
|
||||
cc.Motor.SetPositionAndRotation(TeleportTo.transform.position, TeleportTo.transform.rotation);
|
||||
|
||||
if (OnCharacterTeleport != null)
|
||||
{
|
||||
OnCharacterTeleport(cc);
|
||||
}
|
||||
TeleportTo.isBeingTeleportedTo = true;
|
||||
}
|
||||
}
|
||||
|
||||
isBeingTeleportedTo = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9b74e337ef86d944adf66d1906f11e2
|
||||
timeCreated: 1499314421
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user