Untitled
unknown
plain_text
a year ago
2.8 kB
8
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();
if(isFacingRight)
{
gameObject.transform.rotation = Quaternion.Euler(0,180,0);
//shootBullet.direction = 1f;
}
else
{
gameObject.transform.rotation = Quaternion.Euler(0,0,0);
// shootBullet.direction = 1f;
}
if(movement.x < 0 )
{
isFacingRight = false;
}
else if(movement.x > 0)
{
isFacingRight = true;
}
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.MovePosition(rb.position + movement * CurrentSpeed * Time.fixedDeltaTime);
Vector2.ClampMagnitude(movement, 1f);
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