Implement respawning falling platforms
This commit is contained in:
@@ -8,13 +8,12 @@ public class FallPlatform : MonoBehaviour
|
||||
|
||||
bool falling;
|
||||
Rigidbody2D rb;
|
||||
//Vector3 defposition;
|
||||
Vector3 defposition;
|
||||
|
||||
void Start()
|
||||
{
|
||||
//defposition = transform.position;
|
||||
defposition = transform.parent.position;
|
||||
rb = transform.parent.GetComponent<Rigidbody2D>();
|
||||
|
||||
}
|
||||
private void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
@@ -30,14 +29,18 @@ public class FallPlatform : MonoBehaviour
|
||||
yield return new WaitForSeconds(fallDelay);
|
||||
rb.bodyType = RigidbodyType2D.Dynamic;
|
||||
yield return new WaitForSeconds(resetDelay);
|
||||
//Respawn();
|
||||
transform.parent.GetComponent<Animator>().SetTrigger("respawn");
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
Respawn();
|
||||
}
|
||||
|
||||
//only resets the object script is attached to, need to fix so platform will reset with fall trigger object
|
||||
//private void Respawn()
|
||||
//{
|
||||
//falling = false;
|
||||
//rb.bodyType = RigidbodyType2D.Static;
|
||||
//transform.position = defposition;
|
||||
//}
|
||||
// Use transform.parent to get the object it's attatched to
|
||||
private void Respawn()
|
||||
{
|
||||
falling = false;
|
||||
rb.bodyType = RigidbodyType2D.Static;
|
||||
transform.parent.position = defposition;
|
||||
transform.parent.rotation = Quaternion.identity;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user