-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlatform.cs
46 lines (44 loc) · 1.2 KB
/
Platform.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class Platform : MonoBehaviour
{
public PlatformType platformType;
public float bouncespeed = 100f;
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.contacts[0].normal == Vector2.down)
{
Rigidbody2D rb = collision.gameObject.GetComponent<Rigidbody2D>();
if(rb != null )
{
rb.velocity = Vector2.up * bouncespeed;
}
// Weak Platform
if (platformType == PlatformType.weak)
{
if(GetComponent<Animator>()!=null)
{
GetComponent<Animator>().SetTrigger("Trigger");
Invoke("HideGameObject", 0.4f);
}
}
}
}
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.CompareTag("MainCamera"))
{
gameObject.SetActive(false);
}
}
void HideGameObject()
{
gameObject.SetActive(false);
}
}
public enum PlatformType
{
normal,weak
}