Add push pull power
This commit is contained in:
@@ -4,20 +4,83 @@ using UnityEngine;
|
||||
|
||||
public class ObjectManager : MonoBehaviour
|
||||
{
|
||||
public enum ObjectType {Nothing, Door, PushPull, Drag, Ladder};
|
||||
public enum ObjectType {Nothing, PushPull, Drag};
|
||||
public ObjectType objectType = ObjectType.Nothing;
|
||||
private Rigidbody rigidBody;
|
||||
private MeshRenderer meshRenderer;
|
||||
private PlayerManager playerManager;
|
||||
private bool interact = false;
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
meshRenderer = GetComponent<MeshRenderer>();
|
||||
meshRenderer.materials[1].SetFloat ("_Outline", 0.0f);
|
||||
meshRenderer.materials[1].SetColor("_OutlineColor", new Color(0.5276349f, 0.5566038f, 0.118147f));
|
||||
rigidBody = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (interact)
|
||||
{
|
||||
if (objectType == ObjectType.PushPull)
|
||||
{
|
||||
if (Input.GetKeyUp(KeyCode.E))
|
||||
{
|
||||
if (playerManager.GetPushPullObject() == null)
|
||||
{
|
||||
playerManager.SetPushPullObject(this.gameObject);
|
||||
meshRenderer.materials[1].SetColor("_OutlineColor", new Color(0.5568628f, 0.3785397f, 0.1176471f));
|
||||
}
|
||||
else
|
||||
{
|
||||
playerManager.RemovePushPullObject();
|
||||
meshRenderer.materials[1].SetColor("_OutlineColor", new Color(0.5276349f, 0.5566038f, 0.118147f));
|
||||
playerManager = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (playerManager != null && playerManager.GetPushPullObject() == null)
|
||||
{
|
||||
meshRenderer.materials[1].SetColor("_OutlineColor", new Color(0.5276349f, 0.5566038f, 0.118147f));
|
||||
}
|
||||
if (Input.GetKeyUp(KeyCode.E))
|
||||
{
|
||||
if (playerManager != null)
|
||||
{
|
||||
playerManager.RemovePushPullObject();
|
||||
playerManager = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCollisionStay(Collision collision)
|
||||
{
|
||||
if (collision.gameObject.tag == "Player")
|
||||
{
|
||||
Vector3 hit = collision.contacts[0].normal;
|
||||
if (hit.x != 0 && hit.y == 0)
|
||||
{
|
||||
meshRenderer.materials[1].SetFloat("_Outline", 0.25f);
|
||||
playerManager = collision.gameObject.GetComponent<PlayerManager>();
|
||||
interact = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCollisionExit(Collision collision)
|
||||
{
|
||||
if (collision.gameObject.tag == "Player")
|
||||
{
|
||||
meshRenderer.materials[1].SetFloat("_Outline", 0.0f);
|
||||
interact = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@ public class PlayerManager : MonoBehaviour
|
||||
|
||||
public List<int> activeAbility = new List<int>(); //without ability=0 or null, dubleJump = 1, push/pull = 2, dash = 3
|
||||
private bool dubleJump = true;
|
||||
private GameObject pushPullObject;
|
||||
|
||||
private bool startEating = false;
|
||||
|
||||
@@ -55,6 +56,7 @@ public class PlayerManager : MonoBehaviour
|
||||
{
|
||||
playerAnimator.Play("Die");
|
||||
}
|
||||
AbilityAction();
|
||||
DeactivePowerCube();
|
||||
Move();
|
||||
RunSwitch();
|
||||
@@ -72,6 +74,37 @@ public class PlayerManager : MonoBehaviour
|
||||
Jump();
|
||||
}
|
||||
|
||||
private void AbilityAction()
|
||||
{
|
||||
if (activeAbility.Count > 0 && activeAbility[0] == 2)
|
||||
{
|
||||
if (pushPullObject != null)
|
||||
{
|
||||
pushPullObject.GetComponent<Rigidbody>().MovePosition(
|
||||
pushPullObject.transform.position +
|
||||
(pushPullObject.transform.right * (run ? runSpeed : speed) * Input.GetAxis("Horizontal") * Time.deltaTime)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public GameObject GetPushPullObject()
|
||||
{
|
||||
return pushPullObject;
|
||||
}
|
||||
|
||||
public void SetPushPullObject(GameObject objectPP)
|
||||
{
|
||||
if (activeAbility.Count > 0 && activeAbility[0] == 2) {
|
||||
pushPullObject = objectPP;
|
||||
}
|
||||
}
|
||||
|
||||
public void RemovePushPullObject()
|
||||
{
|
||||
pushPullObject = null;
|
||||
}
|
||||
|
||||
void RunSwitch()
|
||||
{
|
||||
if (Input.GetAxisRaw("Run") > 0)
|
||||
@@ -95,20 +128,25 @@ public class PlayerManager : MonoBehaviour
|
||||
if (Input.GetAxis("Horizontal") > 0)
|
||||
{
|
||||
playerAnimator.SetBool("Walk", true);
|
||||
playerAnimator.transform.rotation = Quaternion.Lerp(
|
||||
playerAnimator.transform.rotation,
|
||||
Quaternion.Euler(playerAnimator.transform.eulerAngles.x, -90f, playerAnimator.transform.eulerAngles.z),
|
||||
localSpeed * Time.deltaTime
|
||||
);
|
||||
if (pushPullObject == null) {
|
||||
playerAnimator.transform.rotation = Quaternion.Lerp(
|
||||
playerAnimator.transform.rotation,
|
||||
Quaternion.Euler(playerAnimator.transform.eulerAngles.x, -90f, playerAnimator.transform.eulerAngles.z),
|
||||
localSpeed * Time.deltaTime
|
||||
);
|
||||
}
|
||||
}
|
||||
else if (Input.GetAxis("Horizontal") < 0)
|
||||
{
|
||||
playerAnimator.SetBool("Walk", true);
|
||||
playerAnimator.transform.rotation = Quaternion.Lerp(
|
||||
playerAnimator.transform.rotation,
|
||||
Quaternion.Euler(playerAnimator.transform.eulerAngles.x, 90f, playerAnimator.transform.eulerAngles.z),
|
||||
localSpeed * Time.deltaTime
|
||||
);
|
||||
if (pushPullObject == null)
|
||||
{
|
||||
playerAnimator.transform.rotation = Quaternion.Lerp(
|
||||
playerAnimator.transform.rotation,
|
||||
Quaternion.Euler(playerAnimator.transform.eulerAngles.x, 90f, playerAnimator.transform.eulerAngles.z),
|
||||
localSpeed * Time.deltaTime
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -132,6 +170,7 @@ public class PlayerManager : MonoBehaviour
|
||||
{
|
||||
if (rigidBody.velocity.y <= 1 && (onGround || (dubleJump && activeAbility.Count > 0 && activeAbility[0] == 1)))
|
||||
{
|
||||
pushPullObject = null;
|
||||
rigidBody.AddForce(
|
||||
(transform.right * (run ? runSpeed : speed) * 5 * Input.GetAxis("Horizontal") * Time.deltaTime) +
|
||||
(transform.up * jump * 10 * Time.deltaTime),
|
||||
@@ -243,10 +282,11 @@ public class PlayerManager : MonoBehaviour
|
||||
|
||||
public void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
if (collision.gameObject.tag == "Objects")
|
||||
if (collision.gameObject.GetComponent<PowerCubeManager>() != null)
|
||||
{
|
||||
Vector3 hit = collision.contacts[0].normal;
|
||||
if (hit.x != 0) {
|
||||
if (hit.x != 0 && hit.y == 0)
|
||||
{
|
||||
powerCubeManager = collision.gameObject.GetComponent<PowerCubeManager>();
|
||||
playerAnimator.SetTrigger("Eat");
|
||||
}
|
||||
|
Reference in New Issue
Block a user