Added collision detection with enemies

This commit is contained in:
MartinRemi 2015-11-16 17:26:18 -05:00
parent ab20f6aca9
commit 26030084ef
5 changed files with 77 additions and 14 deletions

13
Assets/CollisionCheck.cs Normal file
View File

@ -0,0 +1,13 @@
using UnityEngine;
using System.Collections;
public class CollisionCheck : MonoBehaviour {
void OnCollisionEnter2D(Collision2D col)
{
if(col.gameObject.name == "Enemy")
{
Debug.Log(gameObject.GetComponent<Health>().removeHP(1));
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 1a250e41dad412f41a2bdfb3f462c130
timeCreated: 1447711857
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -31,4 +31,9 @@ public class Health : MonoBehaviour {
{
return hp;
}
public void setMaxHP(int amount)
{
maxHP = amount;
}
}

View File

@ -321,6 +321,10 @@ Prefab:
propertyPath: m_Constraints
value: 4
objectReference: {fileID: 0}
- target: {fileID: 431276, guid: b7819e17682d74b45a71d6831a413e0b, type: 2}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: b7819e17682d74b45a71d6831a413e0b, type: 2}
m_IsPrefabParent: 0
@ -328,6 +332,29 @@ Prefab:
GameObject:
m_PrefabParentObject: {fileID: 101678, guid: b7819e17682d74b45a71d6831a413e0b, type: 2}
m_PrefabInternal: {fileID: 1024525637}
--- !u!114 &1189818990
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1189818989}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 28110cf2b286c534c94e41ea7e145ef0, type: 3}
m_Name:
m_EditorClassIdentifier:
maxHP: 3
--- !u!114 &1189818998
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1189818989}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1a250e41dad412f41a2bdfb3f462c130, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1302261674
GameObject:
m_ObjectHideFlags: 0

View File

@ -1,7 +1,8 @@
using UnityEngine;
using System.Collections;
public class PlayerBehavior : MonoBehaviour {
public class PlayerBehavior : MonoBehaviour
{
public float maxSpeed = 50.0f;
@ -17,25 +18,30 @@ public class PlayerBehavior : MonoBehaviour {
private bool facingRight = true;
// Use this for initialization
void Start () {
void Start()
{
rb = gameObject.GetComponent<Rigidbody2D>();
anim = gameObject.GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
if(grounded && Input.GetAxis("Vertical") > 0.0f)
void Update()
{
if (grounded && Input.GetAxis("Vertical") > 0.0f)
{
anim.SetBool("Ground", false);
rb.AddForce(new Vector2(0, jumpForce));
}
//for the shooting animations
if (Input.GetButtonDown ("Fire1")) {
if (Input.GetButtonDown("Fire1"))
{
anim.SetBool("Shooting", true);
} else {
anim.SetBool ("Shooting", false);
}
else
{
anim.SetBool("Shooting", false);
}
}