-
Notifications
You must be signed in to change notification settings - Fork 0
/
StickyPlatform.cs
25 lines (23 loc) · 952 Bytes
/
StickyPlatform.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StickyPlatform : MonoBehaviour
{
private void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.CompareTag("PlayerTag")) // compareTag("PlayerTag_Name") we can also accomplish this way but as singleplayer game(1 player per game session)
//we don't need a tag
{
//then we wanna make Player as a child of MovingPlatform1.platform
Debug.Log("player jumped in!!");
collision.gameObject.transform.SetParent(transform);//here param transform is the transform component of a stickyplatform
}
}
private void OnCollisionExit2D(Collision2D collision)
{
if(collision.gameObject.CompareTag("PlayerTag"))
{
collision.gameObject.transform.SetParent(null);
}
}
}