Untitled
unknown
plain_text
a year ago
2.8 kB
6
Indexable
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Movement : MonoBehaviour { float CurrentSpeed; public float NormSpeed; public float SprintSpeed; public Rigidbody2D rb; public Animator animator; bool IsSprinting; Vector2 movement; bool isFacingRight; public GameObject Smoke; public GasAmnt gasAmnt; public WaterAmnt waterAmnt; float originalwaterLoss; public ShootBullet shootBullet; void Update() { movement.x = Input.GetAxisRaw("Horizontal"); movement.y = Input.GetAxisRaw("Vertical"); Sprint(); bool newFacing = movement.x > 0; if (isFacingRight != newFacing && movement.x != 0) { isFacingRight = newFacing; if(isFacingRight) { gameObject.transform.rotation = Quaternion.Euler(0,180,gameObject.transform.rotation.z); //shootBullet.direction = 1f; } else { gameObject.transform.rotation = Quaternion.Euler(0,0,gameObject.transform.rotation.z); // shootBullet.direction = 1f; } } if(gasAmnt.currentGas == 0 || gasAmnt.currentGas < 0) { Smoke.SetActive(true); NormSpeed = 0.75f; SprintSpeed = 1f; } else { Smoke.SetActive(false); NormSpeed = 4; SprintSpeed = 6; } if(waterAmnt.currentWater == 0 || waterAmnt.currentWater < 0) { shootBullet.FireRate = 1f; shootBullet.BulletForce = 250f; GetComponent<SpriteRenderer>().color = Color.red; } else { shootBullet.FireRate = 10f; shootBullet.BulletForce = 1000f; GetComponent<SpriteRenderer>().color = Color.white; } if(waterAmnt.currentWater == 0 || waterAmnt.currentWater < 0 || gasAmnt.currentGas == 0 || gasAmnt.currentGas < 0) { Smoke.SetActive(true); } else { Smoke.SetActive(false); } } void Start() { } void FixedUpdate() { Move(); } void Move() { rb.velocity = movement * CurrentSpeed; if(Input.GetKey(KeyCode.LeftShift)) { IsSprinting = true; } else { IsSprinting = false; } } void Sprint() { if(IsSprinting) { CurrentSpeed = SprintSpeed; } else { CurrentSpeed = NormSpeed; } } }
Editor is loading...
Leave a Comment