- Home /
Question by
JBrake · Sep 14, 2016 at 12:35 PM ·
scriptingbasicscs0131
2D platformer scripting help, CS0131
Hi, I'm new to unity and have been trying to create a simple 2D platformer. I am trying to create a block that falls after a delay triggered by touching the player. I attempted to create a script based on things I found online and my own knowledge. I think my code works with exception to the CS0131 error. Please assist in solving the CS0131 error or give suggestions to improve my code. Thanks enter code here
Code:
using UnityEngine;
using System.Collections;
public class DelayGrav : MonoBehaviour
{
public float delay = 1f;
private float timer = 0f;
void Start ()
{
}
void Update ()
{
}
void OnColliderHit (Collider other)
{
timer += Time.deltaTime;
if (timer > delay)
RigidbodyConstraints2D.FreezePositionY = false;
}
}
Comment
Answer by DavidWatts · Sep 14, 2016 at 01:12 PM
change OnColliderHit(collider other) to OnCollisionStay2D(collider2D other) and change RigidbodyConstraints2D.FreezePositionY = false; to GetComponent().constraints = RigidbodyConstraints2D.FreezeRotation; that should work.