Hi,
i want to push a Cube with a Player, but only if he touches it (2.5D Game).
Problem is the cube moves at start, even when i set bool to false at start. What i am doing wrong?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Pushable : MonoBehaviour {
private bool collided;
// Use this for initialization
void Start () {
collided = false;
}
void OnCollisionEnter(Collision col)
{
if (col.gameObject.tag == "Player")
{
collided = true;
Debug.Log ("Yes");
}
}
void OnCollisionExit( Collision col)
{
if (col.gameObject.tag == "Player")
{
collided = false;
Debug.Log ("No");
}
}
void Update ()
{
if (collided = true)
{
transform.Translate (Input.GetAxis ("Horizontal") * Time.deltaTime, 0f, 0f);
}
}
}