using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OHareket : MonoBehaviour {
public GameObject oyuncu, gm;
public int hiz = 5, yhiz = 200;
public bool yerde, dead, sagS, solS;
public Rigidbody2D rb;
public AudioClip[] sesler;
public AudioSource audioSource;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody2D>();
dead = gm.GetComponent<GameManager>().dead;
audioSource = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.A))
{
oyuncu.transform.Translate(new Vector3(-hiz * Time.deltaTime, 0 ,0));
oyuncu.transform.localScale = new Vector3(1,1,1);
if (audioSource.isPlaying == false && Input.GetKey(KeyCode.A))
{
audioSource.PlayOneShot(sesler[1]);
sagS = true;
}
else
{
sagS = false;
}
if (sagS==false)
{
audioSource.Stop();
Debug.Log("A");
}
}
if (Input.GetKey(KeyCode.D))
{
oyuncu.transform.Translate(new Vector3(hiz * Time.deltaTime, 0, 0));
oyuncu.transform.localScale = new Vector3(-1, 1, 1);
if (audioSource.isPlaying == false && Input.GetKey(KeyCode.D))
{
audioSource.PlayOneShot(sesler[1]);
Debug.Log("1D");
}
else if (audioSource.isPlaying == true && Input.GetKeyUp(KeyCode.D))
{
audioSource.Stop();
Debug.Log("D");
}
}
if(Input.GetKeyDown(KeyCode.W) && yerde && !dead)
{
rb.AddForceAtPosition(new Vector2(0, yhiz), Vector2.up);
yerde = false;
audioSource.PlayOneShot(sesler[0]);
}
}
private void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.tag == "Yer")
{
yerde = true;
}
}
}