SliderObject.cs 944 Bytes
Newer Older
Michael But's avatar
Michael But committed
1
2
using UnityEngine;

Sebastian Frey's avatar
Sebastian Frey committed
3
namespace _Game.Scripts.Level_Hazards
Michael But's avatar
Michael But committed
4
{
Sebastian Frey's avatar
Sebastian Frey committed
5
	public class SliderObject : MonoBehaviour
Michael But's avatar
Michael But committed
6
	{
Sebastian Frey's avatar
Sebastian Frey committed
7
8
9
10
		private Vector2 _position;
		private Rigidbody2D _rigidbody2D;

		private void Start()
Michael But's avatar
Michael But committed
11
		{
Sebastian Frey's avatar
Sebastian Frey committed
12
			_rigidbody2D = this.GetComponentInParent<Rigidbody2D>();
Michael But's avatar
Michael But committed
13
		}
Sebastian Frey's avatar
Sebastian Frey committed
14
15

		private void OnCollisionEnter2D(Collision2D other)
Michael But's avatar
Michael But committed
16
		{
Sebastian Frey's avatar
Sebastian Frey committed
17
18
			if (other.gameObject.layer == LayerMask.NameToLayer("Player") || other.gameObject.layer == LayerMask.NameToLayer("Enemy") ||
			    other.gameObject.CompareTag("Fire"))
Michael But's avatar
Michael But committed
19
			{
Sebastian Frey's avatar
Sebastian Frey committed
20
21
				_rigidbody2D.velocity = Vector2.zero;
				_rigidbody2D.bodyType = RigidbodyType2D.Static;
Michael But's avatar
Michael But committed
22
23
			}
		}
Unknown's avatar
Unknown committed
24

Sebastian Frey's avatar
Sebastian Frey committed
25
		private void OnCollisionExit2D(Collision2D other)
Unknown's avatar
Unknown committed
26
		{
Sebastian Frey's avatar
Sebastian Frey committed
27
28
29
30
31
32
			if (other.gameObject.layer == LayerMask.NameToLayer("Player") || other.gameObject.layer == LayerMask.NameToLayer("Enemy") ||
			    other.gameObject.CompareTag("Fire"))
			{
				_rigidbody2D.velocity = Vector2.zero;
				_rigidbody2D.bodyType = RigidbodyType2D.Dynamic;
			}
Unknown's avatar
Unknown committed
33
		}
Michael But's avatar
Michael But committed
34
35
	}
}