반응형
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(AudioSource)) ] // unity 창에서 audio사운드 넣을수 있게.
public class Control : MonoBehaviour
{
private float h = 0.0f;
private float v = 0.0f;
private float r = 0.0f;
private float moveSpeed = 10.0f;
private float rotationSpeed = 100.0f;
private Transform playerTr;
private int key;
public AudioClip ksySfx;
private AudioSource audioSource; //오디오 소스 넣을수 있게 unity 배너 추가.
// Start is called before the first frame update
void Start()
{
playerTr = GetComponent<Transform>();
audioSource = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update()
{
h = Input.GetAxis("Horizontal");
v = Input.GetAxis("Vertical");
r = Input.GetAxis("Mouse X");
// Debug.Log("H :" + h.ToString() + "V" + v.ToString());
playerTr.Translate(new Vector3(h, 0, v) * moveSpeed * Time.deltaTime); //Time.deltaTime --> 컴퓨터 성능따라 다르므로 시간 값 같게???
playerTr.Rotate(new Vector3(0, r, 0)* rotationSpeed * Time.deltaTime);
}
private void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.tag =="Key")
{
Destroy(collision.gameObject);
key++;
audioSource.PlayOneShot(ksySfx,1.0f ); // 오디오 소스 실행
Debug.Log("key 개수 :" + key.ToString() );
}
}
}
public으로 audioClip 선언시 아래와 같이 생성됨.
반응형
'프로그래밍 _공부자료. > C++ 공부' 카테고리의 다른 글
리눅스 TCP/IP 클라이언트 기본코드 구조 (0) | 2023.02.11 |
---|---|
mfc 로그 폴더 생성 및 로그 txt 파일 만들기 (1) | 2022.05.12 |
유니티 C# 객체 끼리 충돌 할때 뭔가를 하고 싶을때 ??? 필요한 함수 (0) | 2022.01.06 |
c++로 설문조사 프로그램 만들기. (0) | 2021.12.05 |
배열을 활용하고 순서 짝수는 왼쪽으로 홀수는 오른쪽으로 정렬하여 출력하기. (0) | 2020.02.08 |
댓글