SliderObject.cs 1.07 KB
Newer Older
Michael But's avatar
Michael But committed
1
2
3
4
5
6
7
8
9
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SliderObject : MonoBehaviour
{
	private Rigidbody2D rb;
	public float force;

Unknown's avatar
Unknown committed
10
	/*private void OnTriggerEnter2D(Collider2D collision)
Michael But's avatar
Michael But committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
	{
		if (!GetComponent<Rigidbody2D>())
		{
			rb = GetComponent<Rigidbody2D>();
		}
		else
		{
			Debug.Log("Kein Rigidbody");
		}
		if (collision.gameObject.CompareTag("Water"))
		{
			if(collision.transform.position.x > GetComponent<Transform>().position.x)
			{
				rb.AddForce(new Vector2(-force, 0));
			}else if (collision.transform.position.x < GetComponent<Transform>().position.x)
			{
				rb.AddForce(new Vector2(force, 0));
			}
		}
Unknown's avatar
Unknown committed
30
31
	}*/

Sebastian Frey's avatar
Sebastian Frey committed
32
	private void OnCollisionEnter2D(Collision2D other)
Unknown's avatar
Unknown committed
33
34
35
	{
		if (other.transform.gameObject.tag.Equals("Water"))
		{
Sebastian Frey's avatar
Sebastian Frey committed
36
			gameObject.GetComponent<Rigidbody2D>().velocity = other.gameObject.GetComponent<Rigidbody2D>().velocity;
Unknown's avatar
Unknown committed
37
38
39
		}
	}

Sebastian Frey's avatar
Sebastian Frey committed
40
	private void OnCollisionExit2D(Collision2D other)
Unknown's avatar
Unknown committed
41
42
43
	{
		if (other.transform.gameObject.tag.Equals("Water"))
		{
Sebastian Frey's avatar
Sebastian Frey committed
44
			gameObject.GetComponent<Rigidbody2D>().velocity = Vector2.zero;
Unknown's avatar
Unknown committed
45
		}
Michael But's avatar
Michael But committed
46
47
	}
}