using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.Events;
public class hero : MonoBehaviour
{
Rigidbody2D rb;
Animator anim;
float run;
public bool whenlook;
public GameObject Gun1;
public GameObject Hand1;
public GameObject Hand2;
public static bool jump;
public GameObject Grass;
public GameObject bulleft1;
public GameObject bullright1;
public GameObject Grass2;
public GameObject Grass3;
public bool canshoot = true;
public float timeBetweenFires = 38f;
private float timeTilNextFire = 0.0f;
void Start()
{
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
void Update()
{
if (canshoot == false)
{
if (Time.time > timeBetweenFires)
{
canshoot = true;
}
}
rb.velocity = new Vector2(run, rb.velocity.y);
}
public void rightArrow()
{
whenlook = true;
Flip();
run = 7f;
anim.SetInteger("anim", 2);
}
public void left()
{
whenlook = false;
Flip();
run = -7;
anim.SetInteger("anim", 2);
}
public void stop()
{
run = 0;
anim.SetInteger("anim", 1);
}
public void jump1()
{
if (jump == false)
{
jump = true;
rb.AddForce(transform.up * 18, ForceMode2D.Impulse);
}
}
public void attack()
{
if (canshoot == true)
{
if (whenlook == true)
{
GameObject gameObject = Instantiate(bullright1, new Vector3(transform.position.x + 1.0f, transform.position.y + 0.00f), Quaternion.identity) as GameObject;
}
if (whenlook != true)
{
GameObject gameObject = Instantiate(bulleft1, new Vector3(transform.position.x - 1.0f, transform.position.y + 0.00f), Quaternion.identity) as GameObject;
}
canshoot = false;
}
}
void Flip()
{
if (whenlook == false)
{
transform.localRotation = Quaternion.Euler(0, 0, 0);
}
if (whenlook == true)
{
transform.localRotation = Quaternion.Euler(0, 180, 0);
}
}
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.tag == "Grass")
jump = false;
}
}