Quantcast
Viewing latest article 4
Browse Latest Browse All 16

More collision woes

So im having problems with my code which is Enemy using UnityEngine; using System.Collections; public class Enemy : MonoBehaviour { // Use this for initialization public void OnCollisionEnter(Collision collision) { PlayerHealth playerHealth = collision.gameObject.GetComponent(); if(collision.transform.tag == "Player") { if(playerHealth == null) return; // Get out. playerHealth.ChangeHealth(-10); print ("OW!!!"); } } // Update is called once per frame void Update () { } } And PlayerHealth using UnityEngine; using System.Collections; public class PlayerHealth : MonoBehaviour { // Use this for initialization int Health = 100; public void Start () { } public void ChangeHealth(int howMuch){ this.Health += howMuch; //Are we dead? this.CheckForDead(); } private void CheckForDead(){ if(this.Health < 1) { Application.LoadLevel("GameOver"); } } } my collision detection doesn't work my player (Capsule) is a rigidbody and my capsule (Enemy) is a normal Collider nothing so i made my enemy a rigidbody and deleted the capsule Collider but the enemy now falls through the terrain floor

Viewing latest article 4
Browse Latest Browse All 16

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>