Add power of Ladder climbing
This commit is contained in:
@@ -5,13 +5,14 @@ using UnityEngine.UI;
|
||||
|
||||
public class ObjectManager : MonoBehaviour
|
||||
{
|
||||
public enum ObjectType {Nothing, PushPull, Sign};
|
||||
public enum ObjectType {Nothing, PushPull, Sign, Ladder};
|
||||
public ObjectType objectType = ObjectType.Nothing;
|
||||
private Rigidbody rigidBody;
|
||||
private MeshRenderer meshRenderer;
|
||||
private PlayerManager playerManager;
|
||||
private bool interact = false;
|
||||
public GameObject detailSign;
|
||||
public List<Transform> MovePoints = new List<Transform>();
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
@@ -26,6 +27,10 @@ public class ObjectManager : MonoBehaviour
|
||||
meshRenderer = meshR[1];
|
||||
}
|
||||
}
|
||||
else if (objectType == ObjectType.Ladder)
|
||||
{
|
||||
meshRenderer = GetComponentInChildren<MeshRenderer>();
|
||||
}
|
||||
else
|
||||
{
|
||||
meshRenderer = GetComponent<MeshRenderer>();
|
||||
@@ -67,7 +72,6 @@ public class ObjectManager : MonoBehaviour
|
||||
{
|
||||
detailSign.SetActive(false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -76,12 +80,15 @@ public class ObjectManager : MonoBehaviour
|
||||
{
|
||||
meshRenderer.materials[1].SetColor("_OutlineColor", new Color(0.5276349f, 0.5566038f, 0.118147f));
|
||||
}
|
||||
if (Input.GetKeyUp(KeyCode.E))
|
||||
if (objectType == ObjectType.PushPull)
|
||||
{
|
||||
if (playerManager != null)
|
||||
if (Input.GetKeyUp(KeyCode.E))
|
||||
{
|
||||
playerManager.RemovePushPullObject();
|
||||
playerManager = null;
|
||||
if (playerManager != null)
|
||||
{
|
||||
playerManager.RemovePushPullObject();
|
||||
playerManager = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,6 +104,16 @@ public class ObjectManager : MonoBehaviour
|
||||
meshRenderer.materials[1].SetFloat("_Outline", 2.5f);
|
||||
interact = true;
|
||||
}
|
||||
|
||||
if (objectType == ObjectType.Ladder)
|
||||
{
|
||||
playerManager = other.gameObject.GetComponent<PlayerManager>();
|
||||
playerManager.onLadder = true;
|
||||
if (playerManager.activeAbility.Count > 0 && playerManager.activeAbility[0] == 4) {
|
||||
playerManager.GetComponent<Rigidbody>().useGravity = false;
|
||||
}
|
||||
interact = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +121,14 @@ public class ObjectManager : MonoBehaviour
|
||||
{
|
||||
if (other.gameObject.tag == "Player")
|
||||
{
|
||||
meshRenderer.materials[1].SetFloat("_Outline", 0.0f);
|
||||
if (objectType == ObjectType.Ladder)
|
||||
{
|
||||
playerManager.onLadder = false;
|
||||
playerManager.GetComponent<Rigidbody>().useGravity = true;
|
||||
}
|
||||
if (meshRenderer != null) {
|
||||
meshRenderer.materials[1].SetFloat("_Outline", 0.0f);
|
||||
}
|
||||
interact = false;
|
||||
}
|
||||
}
|
||||
|
@@ -13,14 +13,15 @@ public class PlayerManager : MonoBehaviour
|
||||
public float actualHealth;
|
||||
private float[] actualPowerTimes = new float[] { 0f, 0f, 0f };
|
||||
public bool onGround = true;
|
||||
public bool onLadder = false;
|
||||
private bool run = false;
|
||||
private Animator playerAnimator;
|
||||
private Rigidbody rigidBody;
|
||||
private PowerCubeManager powerCubeManager;
|
||||
private bool interact = false;
|
||||
|
||||
public List<int> activeAbility = new List<int>(); //without ability=0 or null, dubleJump = 1, push/pull = 2, dash = 3
|
||||
public List<GameObject> PowerPrefabs = new List<GameObject>(); //dubleJump = 0, push/pull = 1, dash = 2
|
||||
public List<int> activeAbility = new List<int>(); //without ability=0 or null, dubleJump = 1, push/pull = 2, dash = 3, ladder = 4
|
||||
public List<GameObject> PowerPrefabs = new List<GameObject>(); //dubleJump = 0, push/pull = 1, dash = 2, ladder = 3
|
||||
private bool dubleJump = true;
|
||||
private GameObject pushPullObject;
|
||||
public float dashPower = 40f;
|
||||
@@ -70,7 +71,8 @@ public class PlayerManager : MonoBehaviour
|
||||
powerCubeManager.powerType == PowerCubeManager.PowerType.Artefact ||
|
||||
powerCubeManager.powerType == PowerCubeManager.PowerType.DubleJump ||
|
||||
powerCubeManager.powerType == PowerCubeManager.PowerType.PushPull ||
|
||||
powerCubeManager.powerType == PowerCubeManager.PowerType.Dash
|
||||
powerCubeManager.powerType == PowerCubeManager.PowerType.Dash ||
|
||||
powerCubeManager.powerType == PowerCubeManager.PowerType.Ladder
|
||||
)) {
|
||||
if (Input.GetKeyUp(KeyCode.E))
|
||||
{
|
||||
@@ -118,7 +120,8 @@ public class PlayerManager : MonoBehaviour
|
||||
}
|
||||
else if (activeAbility.Count > 0 && activeAbility[0] == 3)
|
||||
{
|
||||
if (Input.GetKeyUp(KeyCode.D) || Input.GetKeyUp(KeyCode.A) && !dash) {
|
||||
if (Input.GetKeyUp(KeyCode.D) || Input.GetKeyUp(KeyCode.A) && !dash)
|
||||
{
|
||||
if (actualDashTime < Time.time)
|
||||
{
|
||||
if (Input.GetKeyUp(KeyCode.D))
|
||||
@@ -133,7 +136,8 @@ public class PlayerManager : MonoBehaviour
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dashButton == 1 && Input.GetKeyUp(KeyCode.D)) {
|
||||
if (dashButton == 1 && Input.GetKeyUp(KeyCode.D))
|
||||
{
|
||||
rigidBody.AddForce(
|
||||
(transform.right * dashPower * 10 * 5 * 1 * Time.deltaTime) +
|
||||
(transform.up * 1 * 10 * Time.deltaTime),
|
||||
@@ -142,7 +146,7 @@ public class PlayerManager : MonoBehaviour
|
||||
dash = true;
|
||||
dashButton = 0;
|
||||
actualDashTime = Time.time - 1f;
|
||||
}
|
||||
}
|
||||
else if (dashButton == 2 && Input.GetKeyUp(KeyCode.A))
|
||||
{
|
||||
rigidBody.AddForce(
|
||||
@@ -227,11 +231,12 @@ public class PlayerManager : MonoBehaviour
|
||||
|
||||
void Move()
|
||||
{
|
||||
if (onGround) {
|
||||
if (onGround || (onLadder && activeAbility.Count > 0 && activeAbility[0] == 4)) {
|
||||
rigidBody.MovePosition(
|
||||
transform.position +
|
||||
(onLadder && activeAbility.Count > 0 && activeAbility[0] == 4 ? (transform.up * speed * Input.GetAxis("Vertical") * Time.deltaTime) : Vector3.zero) +
|
||||
(transform.right * (run ? runSpeed : speed) * Input.GetAxis("Horizontal") * Time.deltaTime)
|
||||
);
|
||||
);;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,6 +292,12 @@ public class PlayerManager : MonoBehaviour
|
||||
//dash
|
||||
activeAbility[0] = 3;
|
||||
}
|
||||
else if ((powerType.GetHashCode() - 1) == 7)
|
||||
{
|
||||
DropPower();
|
||||
//ladder
|
||||
activeAbility[0] = 4;
|
||||
}
|
||||
else if (actualPowerTimes.Length <= (powerType.GetHashCode()) || actualPowerTimes[powerType.GetHashCode() - 1] < Time.time)
|
||||
{
|
||||
actualPowerTimes[powerType.GetHashCode() - 1] = Time.time + powerTime;
|
||||
@@ -370,14 +381,25 @@ public class PlayerManager : MonoBehaviour
|
||||
{
|
||||
if (other.tag == "Ground" || other.tag == "Objects")
|
||||
{
|
||||
rigidBody.AddForce(
|
||||
(transform.right * (run ? runSpeed : speed) * 5 * Input.GetAxis("Horizontal") * Time.deltaTime) +
|
||||
(transform.up * 10 * Time.deltaTime),
|
||||
ForceMode.VelocityChange
|
||||
);
|
||||
if (!onLadder) {
|
||||
rigidBody.AddForce(
|
||||
(transform.right * (run ? runSpeed : speed) * 5 * Input.GetAxis("Horizontal") * Time.deltaTime) +
|
||||
(transform.up * 10 * Time.deltaTime),
|
||||
ForceMode.VelocityChange
|
||||
);
|
||||
}
|
||||
onGround = false;
|
||||
dash = false;
|
||||
}
|
||||
if (other.gameObject.GetComponent<ObjectManager>() != null)
|
||||
{
|
||||
if (other.gameObject.GetComponent<ObjectManager>().objectType == ObjectManager.ObjectType.Ladder) {
|
||||
rigidBody.AddForce(
|
||||
(transform.right * (run ? runSpeed : speed) * 2.5f * Input.GetAxis("Horizontal") * Time.deltaTime),
|
||||
ForceMode.VelocityChange
|
||||
);
|
||||
}
|
||||
}
|
||||
if (other.gameObject.GetComponent<PowerCubeManager>() != null)
|
||||
{
|
||||
interact = false;
|
||||
|
@@ -5,7 +5,7 @@ using UnityEngine.SceneManagement;
|
||||
|
||||
public class PowerCubeManager : MonoBehaviour
|
||||
{
|
||||
public enum PowerType {Nothing, Bigger, Faster, Jumper, Artefact, DubleJump, PushPull, Dash};
|
||||
public enum PowerType {Nothing, Bigger, Faster, Jumper, Artefact, DubleJump, PushPull, Dash, Ladder};
|
||||
public PowerType powerType = PowerType.Nothing;
|
||||
public float powerTime = 5f;
|
||||
public float powerUnit = 10f;
|
||||
@@ -26,6 +26,10 @@ public class PowerCubeManager : MonoBehaviour
|
||||
{
|
||||
GetComponentInChildren<MeshRenderer>().material.color = Color.white;
|
||||
}
|
||||
if (powerType == PowerType.Ladder)
|
||||
{
|
||||
GetComponentInChildren<MeshRenderer>().material.color = Color.black;
|
||||
}
|
||||
if (powerType == PowerType.Bigger) {
|
||||
GetComponentInChildren<MeshRenderer>().material.color = Color.blue;
|
||||
}
|
||||
@@ -37,7 +41,7 @@ public class PowerCubeManager : MonoBehaviour
|
||||
{
|
||||
GetComponentInChildren<MeshRenderer>().material.color = Color.green;
|
||||
}
|
||||
else if (powerType == PowerType.Artefact || powerType == PowerType.DubleJump || powerType == PowerType.PushPull || powerType == PowerType.Dash)
|
||||
else if (powerType == PowerType.Artefact || powerType == PowerType.DubleJump || powerType == PowerType.PushPull || powerType == PowerType.Dash || powerType == PowerType.Ladder)
|
||||
{
|
||||
meshRenderer = GetComponentInChildren<MeshRenderer>();
|
||||
meshRenderer.materials[1].SetFloat("_Outline", 0.0f);
|
||||
@@ -59,7 +63,7 @@ public class PowerCubeManager : MonoBehaviour
|
||||
{
|
||||
meshRenderer.materials[1].SetFloat("_Outline", 0.4f);
|
||||
}
|
||||
else if (powerType == PowerType.DubleJump || powerType == PowerType.PushPull || powerType == PowerType.Dash)
|
||||
else if (powerType == PowerType.DubleJump || powerType == PowerType.PushPull || powerType == PowerType.Dash || powerType == PowerType.Ladder)
|
||||
{
|
||||
meshRenderer.materials[1].SetFloat("_Outline", 0.01f);
|
||||
}
|
||||
@@ -69,7 +73,7 @@ public class PowerCubeManager : MonoBehaviour
|
||||
{
|
||||
if (other.gameObject.tag == "Player")
|
||||
{
|
||||
if (powerType == PowerType.Artefact || powerType == PowerType.DubleJump || powerType == PowerType.PushPull || powerType == PowerType.Dash)
|
||||
if (powerType == PowerType.Artefact || powerType == PowerType.DubleJump || powerType == PowerType.PushPull || powerType == PowerType.Dash || powerType == PowerType.Ladder)
|
||||
{
|
||||
meshRenderer.materials[1].SetFloat("_Outline", 0.0f);
|
||||
}
|
||||
|
Reference in New Issue
Block a user