Question by
PopTartPie · Mar 03, 2018 at 12:40 AM ·
scripting problemcollisiongame
Contacts not registering?
Trying to make a game in which hitting a cube causes the counter to display a greater number. For some reason only hitting the first cube will raise the counter number. Can anyone help me with this?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DoggyStyle : MonoBehaviour {
public int speed=1;
public Rigidbody rb;
public Text counter;
private int count;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody>();
count = 0;
}
// Update is called once per frame
void Update () {
transform.Rotate(new Vector3(15, 30, 45) * Time.deltaTime*speed);
counter.text = "Count:" + count.ToString();
}
void OnCollisionEnter(Collision other)
{
if (other.gameObject.CompareTag("Player"))
{
rb.isKinematic = false;
speed = 0;
count += 1;
}
}
}
Comment