using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController2 : MonoBehaviour
{
public float radius = 1f;
private float nowY = -3.6f;
const float MAX_Y = 0f;
private bool isJump = false;
private bool isDown = false;
private float jumpSpeed = 0;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//Clamp로 구현
float xPos = Mathf.Clamp(this.transform.position.x, -8f, 8f);
transform.position = new Vector3(xPos, nowY, 0.0f);
//밖으로 못나가게 하기
//if (this.transform.position.x >= 8)
//{
// this.transform.position = new Vector3(8f, nowY, 0);
//}
//else if (this.transform.position.x <= -8)
//{
// this.transform.position = new Vector3(-8f, nowY, 0);
//}
//점프
//if (Input.GetKeyDown(KeyCode.UpArrow))
//{
// isJump = true;
//}
//if (isJump && this.transform.position.y <= -2.0f)
//{
// this.transform.Translate(0, 0.01f, 0);
//}
//jumpSpeed *= 0.99f;
//if(this.transform.position.y > -2.0f)
//{
// isDown = true;
//}
//if(isDown && this.transform.position.y >= nowY)
//{
// this.transform.Translate(0, 0.01f, 0);
//}
if (Input.GetKey(KeyCode.LeftArrow))
{
this.transform.Translate(-0.1f, 0, 0);
}
if (Input.GetKey(KeyCode.RightArrow))
{
this.transform.Translate(0.1f, 0, 0);
}
}
public void RButtonDown()
{
this.transform.Translate(3f, 0, 0);
}
public void LButtonDown()
{
this.transform.Translate(-3f, 0, 0);
}
private void OnDrawGizmos()
{
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(this.transform.position, radius);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ArrowController2 : MonoBehaviour
{
GameObject player;
public float radius = 0.5f;
public float ySpeed = -0.1f;
float distance;
const float GROUND = -4f;
// Start is called before the first frame update
void Start()
{
this.player = GameObject.Find("player");
//this.distance = this.transform.position.y - player.GetComponent<PlayerController2>().transform.position.y;
}
// Update is called once per frame
void Update()
{
this.distance = Vector2.Distance(this.player.transform.position, this.transform.position);
var r = this.radius + player.GetComponent<PlayerController2>().radius;
if (distance <= r)
{
Destroy(this.gameObject);
Debug.Log("고양이랑 부딪힘");
}
if(this.transform.position.y <= GROUND)
{
Destroy(this.gameObject);
Debug.Log("땅이랑 부딪힘");
}
if(this.transform.position.y >= GROUND)
{
this.transform.Translate(0, ySpeed, 0);
}
if (distance < r)
{
//감독관 한테 알려주기
GameObject director = GameObject.Find("App");
director.GetComponent<App>().DecreaseHp();
//충돌
Destroy(this.gameObject); //게임 오브젝트 제거
}
}
private void OnDrawGizmos()
{
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(this.transform.position, radius);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ArrowGenerator : MonoBehaviour
{
public GameObject arrowPrefab;
bool isRun = true;
// Start is called before the first frame update
void Start()
{
}
float delta;
float span = 1f;
// Update is called once per frame
void Update()
{
if(isRun == true)
{
this.delta += Time.deltaTime;
if (this.delta > this.span)
{
this.delta = 0;
GameObject arrowGo = Instantiate(this.arrowPrefab);
int x = Random.Range(-7, 8); //인수의 float은 inclusive int는 inclusive, exclusive
arrowGo.transform.position = new Vector3(x, 5.5f, 0);
}
}
}
public void Stop()
{
//상태를 변경
this.isRun = false;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class App : MonoBehaviour
{
GameObject hpGauge;
public ArrowGenerator arrowGen;
public Text txtTime;
private float delta = 10;
private bool gameover;
public Button btnR;
public Button btnL;
// Start is called before the first frame update
void Start()
{
hpGauge = GameObject.Find("Hp_Gauge");
var player = GameObject.Find("player").GetComponent<PlayerController2>();
this.btnR.onClick.AddListener(() =>
{
player.RButtonDown();
});
this.btnL.onClick.AddListener(() =>
{
player.LButtonDown();
});
}
// Update is called once per frame
void Update()
{
if (this.gameover == false)
{
this.delta -= Time.deltaTime;
if (this.delta <= 0)
{
this.delta = 0;
this.gameover = true;
Debug.Log("Game Over");
}
this.txtTime.text = string.Format("{0:0.0}", this.delta);
}
else if(this.gameover == true)
{
this.txtTime.text = string.Format("GameOver");
this.arrowGen.Stop();
}
}
public void DecreaseHp()
{
var img = this.hpGauge.GetComponent<Image>();
img.fillAmount -= 0.1f;
}
}