Remove project staff
This commit is contained in:
69
Assets/Scripts/DamageObjectsManager.cs
Normal file
69
Assets/Scripts/DamageObjectsManager.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class DamageObjectsManager : MonoBehaviour
|
||||
{
|
||||
public enum ObjectType { Object, HideSpikes, ShowSpikes };
|
||||
public ObjectType objectType = ObjectType.Object;
|
||||
private Animation animation;
|
||||
private bool animate = false;
|
||||
|
||||
public bool instaKill = false;
|
||||
public float damage = 10f;
|
||||
public float damageRate = 5f;
|
||||
private float actualDamageRate = 0f;
|
||||
|
||||
void Start()
|
||||
{
|
||||
animation = gameObject.GetComponent<Animation>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
}
|
||||
|
||||
public void damagePlayer(PlayerManager playerManager)
|
||||
{
|
||||
if (actualDamageRate < Time.time)
|
||||
{
|
||||
actualDamageRate = Time.time + damageRate;
|
||||
playerManager.damage(damage, instaKill);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerStay(Collider other)
|
||||
{
|
||||
if (objectType == ObjectType.HideSpikes)
|
||||
{
|
||||
if (other.gameObject.tag == "Player" && !animate)
|
||||
{
|
||||
Debug.Log(other.tag);
|
||||
animation["Spikes"].speed = 1f;
|
||||
animation["Spikes"].normalizedTime = 0f;
|
||||
animation.Play("Spikes");
|
||||
animate = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (objectType == ObjectType.ShowSpikes)
|
||||
{
|
||||
if (other.gameObject.tag == "Player")
|
||||
{
|
||||
if (actualDamageRate < Time.time)
|
||||
{
|
||||
actualDamageRate = Time.time + damageRate;
|
||||
other.gameObject.GetComponent<PlayerManager>().damage(damage, instaKill);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SpikesBack()
|
||||
{
|
||||
animate = false;
|
||||
animation["Spikes"].speed = -1f;
|
||||
animation.Play("Spikes");
|
||||
}
|
||||
}
|
11
Assets/Scripts/DamageObjectsManager.cs.meta
Normal file
11
Assets/Scripts/DamageObjectsManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 91a5e2ada06678741aadb6c71fc7532b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -4,22 +4,41 @@ using UnityEngine;
|
||||
|
||||
public class PlayerManager : MonoBehaviour
|
||||
{
|
||||
|
||||
public float speed = 25;
|
||||
public float runSpeed = 50;
|
||||
public float speed = 8;
|
||||
public float runSpeed = 20;
|
||||
public float mouseSensitive = 100;
|
||||
public float jump = 30;
|
||||
public bool onGround = false;
|
||||
public float jump = 5;
|
||||
public float health = 100;
|
||||
public float actualHealth;
|
||||
private float[] actualPowerTimes = new float[] { 0f, 0f, 0f };
|
||||
public bool onGround = true;
|
||||
private bool run = false;
|
||||
private Camera playerCamera;
|
||||
private Animator playerAnimator;
|
||||
private Rigidbody rigidBody;
|
||||
public GameObject playerModel;
|
||||
private PowerCubeManager powerCubeManager;
|
||||
|
||||
private bool startEating = false;
|
||||
|
||||
private float saveSpeed;
|
||||
private float saveRunSpeed;
|
||||
private float saveJump;
|
||||
private Vector3 saveSize;
|
||||
private Vector3 savePosition;
|
||||
private Vector3 saveCameraPosition;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
playerCamera = GetComponentInChildren<Camera>();
|
||||
actualHealth = health;
|
||||
playerAnimator = GetComponentInChildren<Animator>();
|
||||
rigidBody = GetComponent<Rigidbody>();
|
||||
|
||||
saveSpeed = speed;
|
||||
saveRunSpeed = runSpeed;
|
||||
saveJump = jump;
|
||||
saveSize = playerAnimator.transform.localScale;
|
||||
savePosition = playerAnimator.transform.localPosition;
|
||||
saveCameraPosition = Camera.main.transform.localPosition;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@@ -29,9 +48,20 @@ public class PlayerManager : MonoBehaviour
|
||||
{
|
||||
Application.Quit(0);
|
||||
}
|
||||
if (actualHealth <= 0)
|
||||
{
|
||||
playerAnimator.Play("Die");
|
||||
}
|
||||
DeactivePowerCube();
|
||||
Move();
|
||||
RunSwitch();
|
||||
Animation();
|
||||
|
||||
if (startEating)
|
||||
{
|
||||
float stepSmaller = 0.8f * Time.deltaTime;
|
||||
powerCubeManager.transform.localScale = Vector3.Slerp(powerCubeManager.transform.localScale, new Vector3(0.01f, 0.01f, 0.01f), stepSmaller);
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
@@ -51,25 +81,36 @@ public class PlayerManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void Die()
|
||||
{
|
||||
Application.LoadLevel(Application.loadedLevel);
|
||||
}
|
||||
|
||||
void Animation()
|
||||
{
|
||||
float localSpeed = 5f;
|
||||
if (Input.GetAxis("Horizontal") > 0)
|
||||
{
|
||||
playerModel.transform.rotation = Quaternion.Lerp(
|
||||
playerModel.transform.rotation,
|
||||
Quaternion.Euler(playerModel.transform.eulerAngles.x, 0f, playerModel.transform.eulerAngles.z),
|
||||
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
|
||||
);
|
||||
}
|
||||
else if (Input.GetAxis("Horizontal") < 0)
|
||||
{
|
||||
playerModel.transform.rotation = Quaternion.Lerp(
|
||||
playerModel.transform.rotation,
|
||||
Quaternion.Euler(playerModel.transform.eulerAngles.x, -180f, playerModel.transform.eulerAngles.z),
|
||||
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
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
playerAnimator.SetBool("Walk", false);
|
||||
}
|
||||
}
|
||||
|
||||
void Move()
|
||||
@@ -82,7 +123,8 @@ public class PlayerManager : MonoBehaviour
|
||||
|
||||
void Jump()
|
||||
{
|
||||
if (Input.GetAxisRaw("Jump") > 0) {
|
||||
if (Input.GetAxisRaw("Jump") > 0)
|
||||
{
|
||||
if (rigidBody.velocity.y <= 1 && onGround)
|
||||
{
|
||||
rigidBody.AddForce(transform.up * jump * 10 * Time.deltaTime, ForceMode.VelocityChange);
|
||||
@@ -90,6 +132,72 @@ public class PlayerManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void ActivePowerCube(float power, float powerTime, PowerCubeManager.PowerType powerType)
|
||||
{
|
||||
if (actualPowerTimes.Length <= (powerType.GetHashCode()) || actualPowerTimes[powerType.GetHashCode() - 1] < Time.time) {
|
||||
actualPowerTimes[powerType.GetHashCode() - 1] = Time.time + powerTime;
|
||||
if (powerType == PowerCubeManager.PowerType.Bigger)
|
||||
{
|
||||
saveSize = playerAnimator.transform.localScale;
|
||||
savePosition = playerAnimator.transform.localPosition;
|
||||
saveCameraPosition = Camera.main.transform.localPosition;
|
||||
|
||||
playerAnimator.transform.localScale = new Vector3(
|
||||
playerAnimator.transform.localScale.x + power,
|
||||
playerAnimator.transform.localScale.y + power,
|
||||
playerAnimator.transform.localScale.z + power
|
||||
);
|
||||
playerAnimator.transform.localPosition = new Vector3(
|
||||
playerAnimator.transform.localPosition.x,
|
||||
playerAnimator.transform.localPosition.y + power * 2,
|
||||
playerAnimator.transform.localPosition.z
|
||||
);
|
||||
Camera.main.transform.localPosition = new Vector3(
|
||||
Camera.main.transform.localPosition.x,
|
||||
Camera.main.transform.localPosition.y,
|
||||
Camera.main.transform.localPosition.z - power * 2
|
||||
);
|
||||
|
||||
}
|
||||
else if (powerType == PowerCubeManager.PowerType.Faster)
|
||||
{
|
||||
saveSpeed = speed;
|
||||
saveRunSpeed = runSpeed;
|
||||
|
||||
speed += power;
|
||||
runSpeed += power;
|
||||
}
|
||||
else if (powerType == PowerCubeManager.PowerType.Jumper)
|
||||
{
|
||||
saveJump = jump;
|
||||
|
||||
jump += power;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DeactivePowerCube()
|
||||
{
|
||||
if (actualPowerTimes[0] != 0f && actualPowerTimes[0] < Time.time)
|
||||
{
|
||||
playerAnimator.transform.localScale = saveSize;
|
||||
playerAnimator.transform.localPosition = savePosition;
|
||||
Camera.main.transform.localPosition = saveCameraPosition;
|
||||
actualPowerTimes[0] = 0f;
|
||||
}
|
||||
if (actualPowerTimes[1] != 0f && actualPowerTimes[1] < Time.time)
|
||||
{
|
||||
speed = saveSpeed;
|
||||
runSpeed = saveRunSpeed;
|
||||
actualPowerTimes[1] = 0f;
|
||||
}
|
||||
if (actualPowerTimes[2] != 0f && actualPowerTimes[2] < Time.time)
|
||||
{
|
||||
jump = saveJump;
|
||||
actualPowerTimes[2] = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.tag == "Ground" || other.tag == "Objects")
|
||||
@@ -111,11 +219,46 @@ public class PlayerManager : MonoBehaviour
|
||||
{
|
||||
if (other.tag == "Ground" || other.tag == "Objects")
|
||||
{
|
||||
if (rigidBody.velocity.y <= 1 && !onGround)
|
||||
{
|
||||
if (rigidBody.velocity.y <= 1 && !onGround) {
|
||||
rigidBody.MovePosition(transform.position);
|
||||
onGround = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
if (collision.gameObject.tag == "Objects")
|
||||
{
|
||||
Vector3 hit = collision.contacts[0].normal;
|
||||
if (hit.x != 0) {
|
||||
powerCubeManager = collision.gameObject.GetComponent<PowerCubeManager>();
|
||||
playerAnimator.SetTrigger("Eat");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void damage(float damage, bool instaKill)
|
||||
{
|
||||
if (instaKill)
|
||||
{
|
||||
actualHealth = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
actualHealth -= damage;
|
||||
}
|
||||
}
|
||||
|
||||
public void StartEatPowerCube()
|
||||
{
|
||||
startEating = true;
|
||||
}
|
||||
|
||||
public void EndEatPowerCube()
|
||||
{
|
||||
startEating = false;
|
||||
ActivePowerCube(powerCubeManager.powerUnit, powerCubeManager.powerTime, powerCubeManager.powerType);
|
||||
Destroy(powerCubeManager.gameObject);
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b520c64fdc2dfed458e743095a22f69d
|
||||
guid: a4db5be0daf431f498fcfbb1baccdde2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
32
Assets/Scripts/PowerCubeManager.cs
Normal file
32
Assets/Scripts/PowerCubeManager.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PowerCubeManager : MonoBehaviour
|
||||
{
|
||||
public enum PowerType {Nothing, Bigger, Faster, Jumper};
|
||||
public PowerType powerType = PowerType.Nothing;
|
||||
public float powerTime = 5f;
|
||||
public float powerUnit = 10f;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (powerType == PowerType.Bigger) {
|
||||
GetComponentInChildren<MeshRenderer>().material.color = Color.blue;
|
||||
}
|
||||
else if (powerType == PowerType.Faster)
|
||||
{
|
||||
GetComponentInChildren<MeshRenderer>().material.color = Color.red;
|
||||
}
|
||||
else if (powerType == PowerType.Jumper)
|
||||
{
|
||||
GetComponentInChildren<MeshRenderer>().material.color = Color.green;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
11
Assets/Scripts/PowerCubeManager.cs.meta
Normal file
11
Assets/Scripts/PowerCubeManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 08fe7369accc1464499b2f2a75559298
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
31
Assets/Scripts/SubDamageObjectScript.cs
Normal file
31
Assets/Scripts/SubDamageObjectScript.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class SubDamageObjectScript : MonoBehaviour
|
||||
{
|
||||
private DamageObjectsManager damageObjectManager;
|
||||
|
||||
void Start()
|
||||
{
|
||||
damageObjectManager = GetComponentInParent<DamageObjectsManager>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnTriggerStay(Collider other)
|
||||
{
|
||||
if (damageObjectManager.objectType == DamageObjectsManager.ObjectType.HideSpikes)
|
||||
{
|
||||
if (other.gameObject.tag == "Player")
|
||||
{
|
||||
damageObjectManager.damagePlayer(other.gameObject.GetComponent<PlayerManager>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/SubDamageObjectScript.cs.meta
Normal file
11
Assets/Scripts/SubDamageObjectScript.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eccc7532abe12e840833011dd7aad947
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
33
Assets/Scripts/SubPlayerScritp.cs
Normal file
33
Assets/Scripts/SubPlayerScritp.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class SubPlayerScritp : MonoBehaviour
|
||||
{
|
||||
private PlayerManager playerManager;
|
||||
|
||||
void Start()
|
||||
{
|
||||
playerManager = GetComponentInParent<PlayerManager>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void StartEatPowerCube()
|
||||
{
|
||||
playerManager.StartEatPowerCube();
|
||||
}
|
||||
|
||||
public void EndEatPowerCube()
|
||||
{
|
||||
playerManager.EndEatPowerCube();
|
||||
}
|
||||
|
||||
public void Die()
|
||||
{
|
||||
playerManager.Die();
|
||||
}
|
||||
}
|
11
Assets/Scripts/SubPlayerScritp.cs.meta
Normal file
11
Assets/Scripts/SubPlayerScritp.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d6a0240c7e91f1644908b3c8bb8d9c96
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user