jordode / Chibi-Knight-2-The-Better-Version

3 stars 1 forks source link

DPS #12

Open jordode opened 6 years ago

jordode commented 6 years ago

Create system where player loses health every second

Interwebsurfer commented 6 years ago

Damage per second? More like damage per frame, lmao

Nyancatisfat commented 6 years ago

using UnityEngine; using System.Collections; using JetBrains.Annotations; using UnityEngine.UI; using UnityEngine.SceneManagement;

public class YesDaddyPlz : MonoBehaviour {

Rigidbody2D myrb;
Transform tf;
float xspeed;
float rotationZ;

Transform groundcheck;
Transform groundcheckr;
Transform groundcheckl;
public float jumpforce;
public LayerMask charmask;
private int juptime;

public bool grounded;
public bool groundedl;
public bool groundedr;
public Text CountText;
public Text loseText;

private int count;

private void OnTriggerStay2D(Collider2D other)
    {
        if (other.gameObject.CompareTag("Triangle"))
        {
            other.gameObject.SetActive(true);
            count = count - 1;
            SetCountText();
        }
    }

// Use this for initialization
void Start()
{
    myrb = this.GetComponent<Rigidbody2D>();
    tf = GetComponent<Transform>();
    groundcheck = GameObject.Find("groundcheck").GetComponent<Transform>();
    // groundcheckl = GameObject.Find ("groundcheck left").GetComponent<Transform> ();
    // groundcheckr = GameObject.Find ("groundcheck right").GetComponent<Transform> ();
    count = 3;
    SetCountText();
    juptime = 0;
    loseText.text = "";
}

void FixedUpdate()
{
    myrb.velocity = new Vector2(xspeed, myrb.velocity.y);
    grounded = Physics2D.OverlapCircle(groundcheck.position, 0.5f, charmask);
    // groundedl = Physics2D.OverlapCircle (groundcheckl.position, 0.5f, charmask);
    // groundedr = Physics2D.OverlapCircle (groundcheckr.position, 0.5f, charmask);

}

// Update is called once per frame
void Update()
{

    {
        rotationZ = Mathf.Clamp(rotationZ, -45, 45);
    }

    if (Input.GetKey(KeyCode.A))
    {
        xspeed = -5;
    }
    else if (Input.GetKey(KeyCode.D))
    {
        xspeed = 5;
    }
    else
    {
        xspeed = 0;
    }

    if (Input.GetKeyDown(KeyCode.Space) && juptime == 0)
    {
        if (grounded || groundedr || groundedl)
        {
            juptime = 25;
        }
    }

    if (juptime > 0)
    {
        juptime = juptime - 1;
        tf.Translate(0.0f, 0.1f, 0.0f);

    }

    tf.rotation = Quaternion.AngleAxis(0.0f, Vector3.forward);  
}

void SetCountText()
{
    CountText.text = "Health: " + count.ToString();
    if (count <= 0)
    {
        loseText.text = "You lose :(";
        SceneManager.LoadScene(1);

    }
}

}

Nyancatisfat commented 6 years ago

that is health with DPS but more like DPF update coming soon, also added jump