I was wondering how to make a script that says when something collides with it will fall and just floats in mid air when nothing collides with it. This is my script:
using UnityEngine;
using System.Collections;
public class Rock : MonoBehaviour {
// Use this for initialization
void Start()
{
Physics2D.gravity = new Vector2(0, 0);
}
// Update is called once per frame
void OnTriggerEnter2D(Collider2D col)
{
if (col.CompareTag("Player"))
{
Physics2D.gravity = new Vector2(0, -1);
}
}
void OnTriggerExit2D(Collider2D col)
{
if (col.CompareTag("Player"))
{
Physics2D.gravity = new Vector2(0, -1);
}
}
}
Any help?