씬 뷰에서 바라보는 시선으로 카메라(오브젝트 방향) 바꾸기 : Ctrl + Shift + F
색칠하기
Texture(그림), 매터리얼 필요
BamsongiController
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BamsongiController : MonoBehaviour
{
private Rigidbody rBody;
[SerializeField]
private float forwardForce = 2000;
private ParticleSystem effect;
// Start is called before the first frame update
private void Awake()
{
this.rBody = this.GetComponent<Rigidbody>();
this.effect = this.GetComponent<ParticleSystem>();
Debug.Log("Awake");
}
void Start()
{
Debug.Log("start");
}
public void Shoot(Vector3 force)
{
Debug.Log("Shoot");
//앞으로 힘으로 줘서 이동시킨다
//앞 ( 0, 0, 1);, Vector3.forward;
//this.rBody.AddForce(방향 * 힘);
this.rBody.AddForce(force);
}
private void OnCollisionEnter(Collision collision)
{
//충돌한 대상의 게임오브젝트를 로그
if(collision.gameObject.tag == "target")
{
Debug.Log("과녁에 충돌");
this.rBody.isKinematic = true;
this.effect.Play();
}
}
}
BamsongiGenerator
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BamsongiGenerator : MonoBehaviour
{
public GameObject bamsongiPrefab;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(Input.GetMouseButtonDown(0))
{
//화면을 터치하면 월드공간에서 Ray를 생성함
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
//생성된 레이를 에디터에서 출력한다.
Debug.DrawRay(ray.origin, ray.direction * 1000f, Color.red, 1f);
//ray.direction.normalized : 단위벡터로 변경
//길이가 1인 벡터 : 방향
Vector3 force = ray.direction.normalized * 2000f;
this.CreateBamsongi(force);
}
}
private void CreateBamsongi(Vector3 force)
{
//새로운 밤송이 생성
GameObject go = Instantiate(this.bamsongiPrefab);
BamsongiController controller = go.GetComponent<BamsongiController>();
controller.Shoot(force);
}
}
..카메라 위치에서 나가도록 수정해야함
'유니티 기초' 카테고리의 다른 글
주말과제 (1) | 2023.08.06 |
---|---|
3D 유니티 LookAt, 유니티 짱, Raycast, 클릭한 위치로 이동 (0) | 2023.08.04 |
pixel_sword (0) | 2023.08.03 |
챕터6 고양이 점프[점프막기, 카메라 아래 최소치 정하기 미완] (0) | 2023.08.02 |
챕터5 고양이탈출 - Prefab (0) | 2023.08.02 |