mirror of
https://github.com/ConjureETS/Labo_2_equ_2_a15.git
synced 2026-03-24 01:21:07 +00:00
Added collision detection with enemies
This commit is contained in:
parent
ab20f6aca9
commit
26030084ef
13
Assets/CollisionCheck.cs
Normal file
13
Assets/CollisionCheck.cs
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/CollisionCheck.cs.meta
Normal file
12
Assets/CollisionCheck.cs.meta
Normal 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:
|
||||
@ -31,4 +31,9 @@ public class Health : MonoBehaviour {
|
||||
{
|
||||
return hp;
|
||||
}
|
||||
|
||||
public void setMaxHP(int amount)
|
||||
{
|
||||
maxHP = amount;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class PlayerBehavior : MonoBehaviour {
|
||||
public class PlayerBehavior : MonoBehaviour
|
||||
{
|
||||
|
||||
public float maxSpeed = 50.0f;
|
||||
|
||||
@ -16,27 +17,32 @@ public class PlayerBehavior : MonoBehaviour {
|
||||
private Animator anim;
|
||||
private bool facingRight = true;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
// Use this for initialization
|
||||
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)
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
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")) {
|
||||
anim.SetBool("Shooting", true);
|
||||
//for the shooting animations
|
||||
if (Input.GetButtonDown("Fire1"))
|
||||
{
|
||||
anim.SetBool("Shooting", true);
|
||||
|
||||
} else {
|
||||
anim.SetBool ("Shooting", false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
anim.SetBool("Shooting", false);
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user