Unity
[예제] 화살쏘기, 점프, 활성비활성
lipnus
2018. 9. 26. 03:38
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Archer : MonoBehaviour {
public KeyCode shotKey;
public GameObject arrowObj;
public Transform shootPosTf;
private int frame = 0;
public GameObject testObj;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
////툴에서 설정한 키를 누르면 화살을 쏜다
//if(Input.GetKeyDown(shotKey)){
// Instantiate(arrowObj).transform.position = shootPosTf.position;
//}
if(Input.GetKeyDown(KeyCode.RightArrow)){
testObj.SetActive(false);
}
if (Input.GetKeyDown(KeyCode.RightArrow)) testObj.SetActive(false);
if (Input.GetKeyDown(KeyCode.LeftArrow)) testObj.SetActive(true);
////스페이스 누르면 점프
if (Input.GetKeyDown(KeyCode.Space)){
GetComponent<Rigidbody2D>().AddForce(Vector3.up * 300f);
}
frame++;
if(frame%100 == 0){
Instantiate(arrowObj).transform.position = shootPosTf.position;
}
}
}
|