This commit is contained in:
jparent 2015-08-23 14:41:12 -04:00
commit d6d7357663
7 changed files with 107 additions and 48 deletions

View File

@ -0,0 +1,13 @@
using UnityEngine;
using System.Collections;
public class MecanimContainer : MonoBehaviour
{
public Child ImmediateParent;
// For Mecanim
public void throw_pillow()
{
ImmediateParent.ThrowMecanimPillow();
}
}

View File

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

View File

@ -417,6 +417,7 @@ GameObject:
m_Component: m_Component:
- 4: {fileID: 436644} - 4: {fileID: 436644}
- 95: {fileID: 9580008} - 95: {fileID: 9580008}
- 114: {fileID: 11484968}
m_Layer: 0 m_Layer: 0
m_Name: Container m_Name: Container
m_TagString: Untagged m_TagString: Untagged
@ -1084,7 +1085,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: e6ffb35a11ff1f545ac22f7ea752cffb, type: 3} m_Script: {fileID: 11500000, guid: e6ffb35a11ff1f545ac22f7ea752cffb, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
PlayerNumber: 1 PlayerNumber: 0
--- !u!114 &11474836 --- !u!114 &11474836
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 1 m_ObjectHideFlags: 1
@ -1097,6 +1098,18 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
minAngleRange: 10 minAngleRange: 10
--- !u!114 &11484968
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 166010}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4d248c94f1991a74ba25229de4e648ea, type: 3}
m_Name:
m_EditorClassIdentifier:
ImmediateParent: {fileID: 11430644}
--- !u!135 &13545904 --- !u!135 &13545904
SphereCollider: SphereCollider:
m_ObjectHideFlags: 1 m_ObjectHideFlags: 1

View File

@ -70,7 +70,7 @@ AnimatorStateTransition:
m_TransitionDuration: .25 m_TransitionDuration: .25
m_TransitionOffset: 0 m_TransitionOffset: 0
m_ExitTime: .659090877 m_ExitTime: .659090877
m_HasExitTime: 1 m_HasExitTime: 0
m_HasFixedDuration: 1 m_HasFixedDuration: 1
m_InterruptionSource: 0 m_InterruptionSource: 0
m_OrderedInterruption: 1 m_OrderedInterruption: 1

View File

@ -2595,10 +2595,6 @@ Prefab:
propertyPath: m_Name propertyPath: m_Name
value: Child 1 value: Child 1
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 11446734, guid: 6dd661a967968c64dbae75c01fac6a09, type: 2}
propertyPath: PlayerNumber
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 6dd661a967968c64dbae75c01fac6a09, type: 2} m_ParentPrefab: {fileID: 100100000, guid: 6dd661a967968c64dbae75c01fac6a09, type: 2}
m_IsPrefabParent: 0 m_IsPrefabParent: 0

View File

@ -115,33 +115,71 @@ public class Child : MonoBehaviour
} }
} }
public void ThrowMecanimPillow()
{
if (pillow == null) return;
Transform target = _autoTarget.GetTarget(transform.forward);
Vector3 direction;
if (target != null)
{
direction = target.transform.position - pillow.transform.position;
}
else
{
direction = transform.forward;
}
direction = direction.normalized;
pillow.gameObject.SetActive(true);
pillow.transform.localPosition = new Vector3(0.109f, -0.407f, 0.389f);
pillow.transform.localEulerAngles = new Vector3(0f, 204.46f, 310.0002f);
AnimationPillow.SetActive(false);
pillow.Throw(direction * ThrowForce);
pillow.IsOwned = false;
target = null;
pillow = null;
}
void OnTriggerEnter(Collider other) { void OnTriggerEnter(Collider other) {
if (other.tag == "Pillow"){ if (other.tag == "Pillow"){
Pillow incomingPillow = other.GetComponent<Pillow>(); Pillow incomingPillow = other.GetComponent<Pillow>();
// picking up a pillow // getting hit by a pillow
if (this.pillow == null && incomingPillow.IsPickable) { if (incomingPillow.IsThrown) {
Debug.Log("abc");
if (incomingPillow.Owner != this)
{
//player is hit
Debug.Log("Child is hit by a pillow");
Push(other.GetComponent<Rigidbody>().velocity.normalized * 10 * hitPushBackForce);
Destroy(other.gameObject);
}
}
// picking up a pillow
else if (this.pillow == null && incomingPillow.IsPickable) {
Debug.Log("def");
pillow = incomingPillow; pillow = incomingPillow;
pillow.transform.parent = transform; // make the pillow a child of Child pillow.transform.parent = transform; // make the pillow a child of Child
pillow.transform.localPosition = new Vector3(0f, 1.5f, 0f); pillow.gameObject.SetActive(false);
pillow.GetComponent<Rigidbody>().isKinematic = true; // dont make pillow obey to gravity when in a child's hands pillow.GetComponent<Rigidbody>().isKinematic = true; // dont make pillow obey to gravity when in a child's hands
pillow.IsOwned = true; pillow.IsOwned = true;
pillow.Owner = this;
AnimationPillow.SetActive(true);
// TODO: place the pillow correctly or animate or something... // TODO: place the pillow correctly or animate or something...
} }
// getting hit by a pillow
else if (incomingPillow.IsThrown) {
//player is hit
Debug.Log("Child is hit by a pillow");
Push( other.GetComponent<Rigidbody>().velocity.normalized * 10 * hitPushBackForce);
Destroy(other.gameObject);
}
} }
} }
@ -208,27 +246,6 @@ public class Child : MonoBehaviour
if (_isInLava) return; if (_isInLava) return;
if (pillow != null) { if (pillow != null) {
Vector3 direction;
Transform target = _autoTarget.GetTarget(transform.forward);
if (target != null) {
direction = target.transform.position - pillow.transform.position;
}
else {
direction = transform.forward;
}
direction = direction.normalized;
pillow.Throw(direction * ThrowForce);
pillow.IsOwned = false;
pillow = null;
target = null;
Animator.SetTrigger("StartAttack"); Animator.SetTrigger("StartAttack");
} }
} }
@ -268,11 +285,6 @@ public class Child : MonoBehaviour
void OnCollisionStay(Collision collision) void OnCollisionStay(Collision collision)
{ {
if (collision.gameObject.tag == "Walls")
{
Debug.Log(_isPushed);
}
if (collision.gameObject.tag == "Lava") if (collision.gameObject.tag == "Lava")
{ {
_invulnerableTime += Time.deltaTime; _invulnerableTime += Time.deltaTime;
@ -291,9 +303,10 @@ public class Child : MonoBehaviour
} }
else if (_wasPushed && collision.gameObject.tag == "Walls") else if (_wasPushed && collision.gameObject.tag == "Walls")
{ {
/*
_wasPushed = false; _wasPushed = false;
Push(Vector3.Reflect(_pushedDir.normalized, collision.contacts[0].normal) * _pushedDir.magnitude); Push(Vector3.Reflect(_pushedDir.normalized, collision.contacts[0].normal) * _pushedDir.magnitude);*/
} }
} }
@ -333,4 +346,4 @@ public class Child : MonoBehaviour
{ {
ActivateVibration(false); ActivateVibration(false);
} }
} }

View File

@ -31,6 +31,15 @@ public class Pillow : MonoBehaviour {
} }
} }
private Child _owner;
public Child Owner
{
get { return _owner; }
set { _owner = value; }
}
// Use this for initialization // Use this for initialization
void Start () { void Start () {
_col = GetComponent<Collider>(); _col = GetComponent<Collider>();
@ -71,7 +80,10 @@ public class Pillow : MonoBehaviour {
} }
void OnCollisionEnter(Collision other) { void OnCollisionEnter(Collision other) {
if (!IsPickable && !IsLost) { Child child = other.gameObject.GetComponent<Child>();
if (!IsPickable && !IsLost && Owner == child)
{
// on first collision, revert the pillow as pickable // on first collision, revert the pillow as pickable
MakePickable(); MakePickable();
} }