SLEAPY_SMURF/Assets/Scripts/player.cs

115 lines
3.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class player : MonoBehaviour
{
[SerializeField] private GameObject mündiEffekt;
public Transform mündiMinekuAsukoht;
private bool lendab;
public ForceMode forcemode;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.W))
{
transform.rotation = Quaternion.Euler(0, 360, 0);
}
if (Input.GetKey(KeyCode.S))
{
transform.rotation = Quaternion.Euler(0, 180, 0);
}
if (Input.GetKeyDown(KeyCode.Space) & !lendab)
{
GetComponent<Rigidbody>().AddForce(new Vector3(0, 2000), forcemode);
lendab = true;
//transform.position += new Vector3(0, 20) * Time.deltaTime;
}
if (Input.GetKey(KeyCode.D))
{
transform.position += new Vector3(20, 0) * Time.deltaTime;
transform.rotation = Quaternion.Euler(0, 90, 0);
}
if (Input.GetKey(KeyCode.A))
{
transform.position += new Vector3(-20, 0) * Time.deltaTime;
transform.rotation = Quaternion.Euler(0, 270, 0);
}
}
private bool kasLendab() {
if (gameObject.transform.position.y <= 1143.05)
return lendab = false;
else
return lendab = true;
}
public void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.tag == "Ground")
{
lendab = false;
}
Debug.Log(collision);
}
public void OnTriggerEnter(Collider other)
{
if (other.tag == "kast")
{
var targetFollower = GetComponent<TargetFollower>();
targetFollower.kaesolevAsi = other.gameObject.transform;
targetFollower.kaesolevAsi.DOScale(Vector3.one * 0.4f, 1f);
targetFollower.kaesolevAsi.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
}
else if (other.tag == "npc")
{
var targetFollower = GetComponent<TargetFollower>();
if (targetFollower.kaesolevAsi == null) return;
var müntideArv = targetFollower.kaesolevAsi.GetComponent<Kast>().müntideArv;
FindObjectOfType<MüntideLugeja>().AnnaMünte(müntideArv);
Destroy(targetFollower.kaesolevAsi.gameObject);
for (var i = 0; i < müntideArv; i++)
{
var münt = Instantiate(mündiEffekt, transform.position, Quaternion.identity);
//münt.transform.localScale = Vector3.zero;
var seq = DOTween.Sequence();
seq.Append(münt.transform.DOScale(Vector3.one, i).SetEase(Ease.InOutQuad));
var tf = münt.AddComponent<TargetFollower>();
tf.kiirus = 5f - i * (0.5f);
tf.kasi = mündiMinekuAsukoht;
tf.kaesolevAsi = münt.transform;
Destroy(münt, 5f - i * (0.5f));
//seq.Append(münt.transform.DOScale(Vector3.one, i).SetEase(Ease.InOutQuad));
//seq.Append(münt.transform.DOScale(Vector3.zero, i).SetEase(Ease.InOutQuad)).OnComplete(() => { Destroy(münt); });
}
}
}
public void Surm()
{
transform.position = new Vector3(-78, 1138, 0);
}
}