Separate respawn script
Make respawning a separate script; make Bones respawnable
This commit is contained in:
@@ -90,6 +90,7 @@ GameObject:
|
||||
- component: {fileID: 5205514565969078994}
|
||||
- component: {fileID: 4323437100190106747}
|
||||
- component: {fileID: 9112988359646506999}
|
||||
- component: {fileID: 8542321013335259419}
|
||||
- component: {fileID: 2791557175355662981}
|
||||
- component: {fileID: 3406519100105273690}
|
||||
- component: {fileID: 251648003544978305}
|
||||
@@ -231,6 +232,20 @@ MonoBehaviour:
|
||||
jumpLenience: 0.1
|
||||
timeUnableToBeDeclaredNotJumping: 0.1
|
||||
groundCheckDistance: 0.1
|
||||
--- !u!114 &8542321013335259419
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6546762253351562952}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 8ce1d588594ee416e9ab629d0b8c07dd, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
spawnPoint: {x: 0, y: 0}
|
||||
respawnTag: Platformer Hazard
|
||||
--- !u!61 &2791557175355662981
|
||||
BoxCollider2D:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -298,11 +298,6 @@ BoxCollider2D:
|
||||
m_AutoTiling: 0
|
||||
m_Size: {x: 0.0625, y: 0.5}
|
||||
m_EdgeRadius: 0
|
||||
--- !u!1 &56161603 stripped
|
||||
GameObject:
|
||||
m_CorrespondingSourceObject: {fileID: 6546762253351562952, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
m_PrefabInstance: {fileID: 2115507663656225473}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
--- !u!1 &292682714
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -576,72 +571,97 @@ BoxCollider2D:
|
||||
m_AutoTiling: 0
|
||||
m_Size: {x: 0.0625, y: 0.5}
|
||||
m_EdgeRadius: 0
|
||||
--- !u!1001 &543363806
|
||||
PrefabInstance:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 2
|
||||
m_Modification:
|
||||
serializedVersion: 3
|
||||
m_TransformParent: {fileID: 0}
|
||||
m_Modifications:
|
||||
- target: {fileID: 627266363752542778, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
propertyPath: m_LocalPosition.x
|
||||
value: 12
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 627266363752542778, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
propertyPath: m_LocalPosition.y
|
||||
value: 6.5
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 627266363752542778, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
propertyPath: m_LocalPosition.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 627266363752542778, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
propertyPath: m_LocalRotation.w
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 627266363752542778, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
propertyPath: m_LocalRotation.x
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 627266363752542778, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
propertyPath: m_LocalRotation.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 627266363752542778, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
propertyPath: m_LocalRotation.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 627266363752542778, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.x
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 627266363752542778, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 627266363752542778, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6546762253351562952, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
propertyPath: m_Name
|
||||
value: Player 2
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 9112988359646506999, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
propertyPath: player
|
||||
value: 2
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_RemovedGameObjects: []
|
||||
m_AddedGameObjects: []
|
||||
m_AddedComponents: []
|
||||
m_SourcePrefab: {fileID: 100100000, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
--- !u!1 &543363807 stripped
|
||||
--- !u!1 &804358384
|
||||
GameObject:
|
||||
m_CorrespondingSourceObject: {fileID: 6546762253351562952, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
m_PrefabInstance: {fileID: 543363806}
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 804358387}
|
||||
- component: {fileID: 804358386}
|
||||
- component: {fileID: 804358385}
|
||||
m_Layer: 0
|
||||
m_Name: Player Manager
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &804358385
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 804358384}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 33e0fad1e452e0140bc99e780d4dda4f, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
players: []
|
||||
spawnPosition: {x: -2, y: 15}
|
||||
--- !u!114 &804358386
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 804358384}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 621567455fd1c4ceb811cc8a00b6a1a5, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_NotificationBehavior: 0
|
||||
m_MaxPlayerCount: -1
|
||||
m_AllowJoining: 1
|
||||
m_JoinBehavior: 0
|
||||
m_PlayerJoinedEvent:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_PlayerLeftEvent:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_JoinAction:
|
||||
m_UseReference: 0
|
||||
m_Action:
|
||||
m_Name:
|
||||
m_Type: 0
|
||||
m_ExpectedControlType:
|
||||
m_Id: 9b26d698-45b8-4b09-bfa5-81c3a8afe391
|
||||
m_Processors:
|
||||
m_Interactions:
|
||||
m_SingletonActionBindings: []
|
||||
m_Flags: 0
|
||||
m_Reference: {fileID: 0}
|
||||
m_PlayerPrefab: {fileID: 6546762253351562952, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
m_SplitScreen: 0
|
||||
m_MaintainAspectRatioInSplitScreen: 0
|
||||
m_FixedNumberOfSplitScreens: -1
|
||||
m_SplitScreenRect:
|
||||
serializedVersion: 2
|
||||
x: 0
|
||||
y: 0
|
||||
width: 1
|
||||
height: 1
|
||||
--- !u!4 &804358387
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 804358384}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: -2, y: 15, z: -10.092264}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &1178732237
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -12299,6 +12319,7 @@ GameObject:
|
||||
- component: {fileID: 1355961160}
|
||||
- component: {fileID: 1355961159}
|
||||
- component: {fileID: 1355961161}
|
||||
- component: {fileID: 1355961162}
|
||||
m_Layer: 0
|
||||
m_Name: Bones
|
||||
m_TagString: Untagged
|
||||
@@ -12367,10 +12388,25 @@ Rigidbody2D:
|
||||
m_ExcludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_Interpolate: 0
|
||||
m_Interpolate: 1
|
||||
m_SleepingMode: 1
|
||||
m_CollisionDetection: 0
|
||||
m_CollisionDetection: 1
|
||||
m_Constraints: 0
|
||||
--- !u!114 &1355961162
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1355961158}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 8ce1d588594ee416e9ab629d0b8c07dd, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
spawnPoint: {x: 14.08, y: 14.08}
|
||||
spawnPointIsInitialPosition: 1
|
||||
respawnTag: Platformer Hazard
|
||||
--- !u!1 &1399509873
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -13121,67 +13157,6 @@ BoxCollider2D:
|
||||
m_AutoTiling: 0
|
||||
m_Size: {x: 0.0625, y: 0.5}
|
||||
m_EdgeRadius: 0
|
||||
--- !u!1001 &2115507663656225473
|
||||
PrefabInstance:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 2
|
||||
m_Modification:
|
||||
serializedVersion: 3
|
||||
m_TransformParent: {fileID: 0}
|
||||
m_Modifications:
|
||||
- target: {fileID: 627266363752542778, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
propertyPath: m_LocalPosition.x
|
||||
value: -23.5
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 627266363752542778, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
propertyPath: m_LocalPosition.y
|
||||
value: -4.5
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 627266363752542778, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
propertyPath: m_LocalPosition.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 627266363752542778, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
propertyPath: m_LocalRotation.w
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 627266363752542778, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
propertyPath: m_LocalRotation.x
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 627266363752542778, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
propertyPath: m_LocalRotation.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 627266363752542778, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
propertyPath: m_LocalRotation.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 627266363752542778, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.x
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 627266363752542778, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 627266363752542778, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6546762253351562952, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
propertyPath: m_Name
|
||||
value: Player 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 9112988359646506999, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
propertyPath: player
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_RemovedGameObjects: []
|
||||
m_AddedGameObjects: []
|
||||
m_AddedComponents: []
|
||||
m_SourcePrefab: {fileID: 100100000, guid: ebfcd0c20e648c041b2f37e0de297d69, type: 3}
|
||||
--- !u!1001 &8682934954266721942
|
||||
PrefabInstance:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -13193,7 +13168,7 @@ PrefabInstance:
|
||||
- target: {fileID: 1277363986118001863, guid: e659ce6dc4d58ff4f9726fa05e1bab20, type: 3}
|
||||
propertyPath: player
|
||||
value:
|
||||
objectReference: {fileID: 56161603}
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1277363986118001863, guid: e659ce6dc4d58ff4f9726fa05e1bab20, type: 3}
|
||||
propertyPath: players.Array.size
|
||||
value: 2
|
||||
@@ -13201,11 +13176,11 @@ PrefabInstance:
|
||||
- target: {fileID: 1277363986118001863, guid: e659ce6dc4d58ff4f9726fa05e1bab20, type: 3}
|
||||
propertyPath: 'players.Array.data[0]'
|
||||
value:
|
||||
objectReference: {fileID: 56161603}
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1277363986118001863, guid: e659ce6dc4d58ff4f9726fa05e1bab20, type: 3}
|
||||
propertyPath: 'players.Array.data[1]'
|
||||
value:
|
||||
objectReference: {fileID: 543363807}
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 2927715701766480068, guid: e659ce6dc4d58ff4f9726fa05e1bab20, type: 3}
|
||||
propertyPath: m_Name
|
||||
value: Platformer Camera
|
||||
@@ -13261,7 +13236,6 @@ SceneRoots:
|
||||
m_Roots:
|
||||
- {fileID: 8682934954266721942}
|
||||
- {fileID: 322321}
|
||||
- {fileID: 2115507663656225473}
|
||||
- {fileID: 543363806}
|
||||
- {fileID: 1758254989}
|
||||
- {fileID: 1355961160}
|
||||
- {fileID: 804358387}
|
||||
|
||||
@@ -3,8 +3,6 @@ using UnityEngine;
|
||||
|
||||
public class PlatformerCameraMovement : MonoBehaviour
|
||||
{
|
||||
public List<GameObject> players;
|
||||
|
||||
private Vector3 start;
|
||||
private Vector3 target;
|
||||
public float weight;
|
||||
@@ -17,7 +15,9 @@ public class PlatformerCameraMovement : MonoBehaviour
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (PlayerManager.Instance.players.Count == 0) return;
|
||||
List<GameObject> players = PlayerManager.Instance.players;
|
||||
|
||||
if (players.Count == 0) return;
|
||||
|
||||
Vector3 playerAverage = Vector3.zero;
|
||||
foreach (GameObject player in players)
|
||||
|
||||
@@ -31,9 +31,6 @@ public class PlayerMovement : MonoBehaviour
|
||||
private Rigidbody2D body;
|
||||
private BoxCollider2D collide;
|
||||
private PlayerInput input;
|
||||
|
||||
private Vector2 spawnPosition;
|
||||
|
||||
private bool jumpInputStillValid = false;
|
||||
private float lastTimeJumpPressed;
|
||||
|
||||
@@ -49,7 +46,7 @@ public class PlayerMovement : MonoBehaviour
|
||||
|
||||
void Start()
|
||||
{
|
||||
spawnPosition = transform.position;
|
||||
GetComponent<RespawnOnTriggerEnter>().spawnPoint = transform.position;
|
||||
|
||||
body = GetComponent<Rigidbody2D>();
|
||||
collide = GetComponent<BoxCollider2D>();
|
||||
@@ -156,20 +153,6 @@ public class PlayerMovement : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
if (collision.gameObject.CompareTag("Platformer Hazard"))
|
||||
{
|
||||
Respawn();
|
||||
}
|
||||
}
|
||||
|
||||
private void Respawn()
|
||||
{
|
||||
transform.position = spawnPosition;
|
||||
body.linearVelocity = Vector2.zero;
|
||||
}
|
||||
|
||||
public bool IsBasicallyGrounded()
|
||||
{
|
||||
if (IsPhysicallyGrounded())
|
||||
|
||||
28
Assets/RespawnOnTriggerEnter.cs
Normal file
28
Assets/RespawnOnTriggerEnter.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class RespawnOnTriggerEnter : MonoBehaviour
|
||||
{
|
||||
public Vector2 spawnPoint;
|
||||
public bool spawnPointIsInitialPosition = false;
|
||||
public string respawnTag;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (spawnPointIsInitialPosition)
|
||||
{
|
||||
spawnPoint = transform.position;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
if (other.CompareTag(respawnTag))
|
||||
{
|
||||
transform.position = spawnPoint;
|
||||
if (TryGetComponent<Rigidbody2D>(out var rb))
|
||||
{
|
||||
rb.linearVelocity = Vector2.zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/RespawnOnTriggerEnter.cs.meta
Normal file
2
Assets/RespawnOnTriggerEnter.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ce1d588594ee416e9ab629d0b8c07dd
|
||||
8412
mono_crash.0.0.json
Normal file
8412
mono_crash.0.0.json
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user