// Player 소스
public class Player : MonoBehaviour{
bool isJump=false;
public Score=0;
public float jumpPower=10f;
public Text Scoretext;
Rigidbody rigid;
AudioSource audio;
void Awake(){
rigid=GetComponent<Rigidbody>();
audio=gameObjecet.GetComponet<AudioSourc>();
}
void Update(){
if(Input.GetButtonDown(Jump)&& isJump != false){
jump();
isJump=true;
}
Scoretext.text=Score.ToString()+"점";
}
void FixedUpdate(){
float h=input.GetAxisRaw("Horizontal");
float v=input.GetAxisRaw("Vertical");
rigid.AddForce(new Vector3(h,0,v),ForceMode.Impulse);
}
private void OnCollisionEnter(Collision collision){
if(collision.gameObject.name=="Floor")isJump=False;
}
private void OnTrigerEnter(Colider other){
if(other.name=="Goal"){
SceneManager.LoadScene("Scene01");
}
}
private void jump(){
rigid.AddForce(new Vector3(0,jumpPower,0),ForceMode.Impulse);
}
public void PlayOn(){
audio.Play();
}
}
// Item 소스
public class Item : MonoBehaviour{
private void OnTrigerEnter(Colider other){
if(other.name=="Player"){//other.tag=="Player"
Player player=other.GetComponent<PlayerBall>();
player.score+=100;
palyer.PlayOn();
gameObjecet.SetActive(false);
}
}
}
//CameraMove 소스
public class CameraMove : MonoBehaviour{
Transform playerTransform;
Vector3 Offset;
void Awak(){
playerTransform=GameObject.FindGameObjectWithTag("Player").transform;
Offset=transform.position -playerTransform.position;
}
void LateUpdate(){
transform.position=playerTransform.position + Offset;
}
}
'잡다한지식 > 게임개발' 카테고리의 다른 글
유니티 2019-11-27 공부 (0) | 2019.11.27 |
---|---|
유니티2D 관련지식 (0) | 2019.11.19 |
유니티 UI관련 지식 (0) | 2019.11.17 |
유니티 컴퍼넌트관련 지식 (0) | 2019.11.16 |
유니티 참고용 소스(함수, 응용) 및 지식// C# (0) | 2019.11.13 |