- Added CollisionEnter scripts

This commit is contained in:
Samuel 2015-08-11 14:06:23 -04:00
parent 5837a7f2c9
commit 1571326998
3 changed files with 90 additions and 35 deletions

View File

@ -100,8 +100,8 @@ GameObject:
- 23: {fileID: 90076752}
- 114: {fileID: 90076751}
m_Layer: 0
m_Name: CollisionField
m_TagString: Untagged
m_Name: VampireCollisionField
m_TagString: VampirePlayer
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
@ -126,9 +126,11 @@ MonoBehaviour:
m_GameObject: {fileID: 90076749}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8a1ccd1ad32d6bc4fb600c5b5720e01c, type: 3}
m_Script: {fileID: 11500000, guid: c1cd93867b8a1d7459a4fb92cac63854, type: 3}
m_Name:
m_EditorClassIdentifier:
defaultHp: 250
defaultAttack: 100
--- !u!23 &90076752
MeshRenderer:
m_ObjectHideFlags: 0
@ -185,7 +187,6 @@ GameObject:
- 23: {fileID: 209133696}
- 143: {fileID: 209133700}
- 54: {fileID: 209133701}
- 114: {fileID: 209133702}
m_Layer: 0
m_Name: Vampire
m_TagString: VampirePlayer
@ -281,17 +282,6 @@ Rigidbody:
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!114 &209133702
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 209133695}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c1cd93867b8a1d7459a4fb92cac63854, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &215281597
GameObject:
m_ObjectHideFlags: 0
@ -448,7 +438,7 @@ GameObject:
- 33: {fileID: 1674696789}
- 65: {fileID: 1674696788}
- 23: {fileID: 1674696787}
- 114: {fileID: 1674696790}
- 54: {fileID: 1674696791}
m_Layer: 0
m_Name: Human
m_TagString: Human
@ -463,7 +453,7 @@ Transform:
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1674696785}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 5, z: 25}
m_LocalPosition: {x: 0, y: 15, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 2081975386}
@ -512,17 +502,21 @@ MeshFilter:
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1674696785}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!114 &1674696790
MonoBehaviour:
--- !u!54 &1674696791
Rigidbody:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1674696785}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8a1ccd1ad32d6bc4fb600c5b5720e01c, type: 3}
m_Name:
m_EditorClassIdentifier:
serializedVersion: 2
m_Mass: 1
m_Drag: 0
m_AngularDrag: .0500000007
m_UseGravity: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!1 &1780458434
GameObject:
m_ObjectHideFlags: 0
@ -606,8 +600,8 @@ GameObject:
- 23: {fileID: 2081975383}
- 114: {fileID: 2081975387}
m_Layer: 0
m_Name: CollisionField
m_TagString: Untagged
m_Name: HumanCollisionField
m_TagString: Human
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
@ -678,3 +672,5 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 8a1ccd1ad32d6bc4fb600c5b5720e01c, type: 3}
m_Name:
m_EditorClassIdentifier:
defaultHp: 250
defaultAttack: 100

View File

@ -7,19 +7,19 @@ using JetBrains.Annotations;
public class Unit : MonoBehaviour
{
private LinkedList<Command> commandList;
public int defaultHp = 250;
public int defaultAttack = 100;
// Use this for initialization
void Start ()
{
// initialize default hp
//Hp = defaultHp;
// initialize default attack
Attack = defaultAttack;
// initialize default team
// initialize default specie
}
// Update is called once per frame
void Update ()
{
//
isDead = false;
}
/// <summary>
@ -38,7 +38,8 @@ public class Unit : MonoBehaviour
#region Unit properties
public int HP { get; set; }
public int Hp { get; set; }
public int Attack { get; set; }
//public bool isAlly { get; set; }
//public bool isHuman { get; set; }

View File

@ -7,15 +7,27 @@ using System.Collections;
public class VampireUnit : Unit
{
// Use this for initialization
void Start ()
{
InitializeDefaultTag();
// initialize default hp
//Hp = defaultHp;
// initialize default attack
Attack = defaultAttack;
// initialize default team
// initialize default specie
isDead = false;
}
// Update is called once per frame
void Update ()
{
if (isDead)
{
// TODO play dead animation before destroying unit
DestroyUnit();
}
}
private void InitializeDefaultTag()
@ -35,4 +47,50 @@ public class VampireUnit : Unit
this.gameObject.tag = Tag;
}
}
void CaptureHuman(Unit unit)
{
// TODO either add the human as a squad member or change it's tag to vampireHuman
// when the player is transformed we just make VampireUnit vampireUnit2 = (VampireUnit) unit;
Debug.Log("Entered in collision with: " + unit.Tag );
}
void AttackEnemy(Unit unit)
{
// compute the amount of hp reduced to this unit
unit.Hp -= Attack; // we remove some hp of the unit that was
Debug.Log("Attacked the ennemy : " + unit.Tag);
}
/// <summary>
/// Destroy the current unit
/// </summary>
void DestroyUnit()
{
Destroy(this.gameObject);
}
void OnTriggerEnter(Collider collider)
{
//var objectTag = collider.gameObject;
// check if the game object have an attached Unit class
//switch(objectTag.GetType())
var unitComponent = collider.GetComponent<Unit>();
if (unitComponent != null)
{
// check if the unit is not a friendly one
if (this.Tag != unitComponent.Tag)
{
if (unitComponent.Tag.Equals(TagManager.Human))
{
CaptureHuman(unitComponent);
}
else // we know that it's an ennemy
{
AttackEnemy(unitComponent);
}
}
}
}
}