밤송이를 프리팹으로
화면을 터치하면
밤송이가 마우스 터치한 곳으로 날라간다
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BamsongiController : MonoBehaviour
{
private Rigidbody rbody;
private ParticleSystem particle;
public Vector3 direct;
void Start()
{
this.rbody = this.GetComponent<Rigidbody>();
this.particle = this.GetComponent<ParticleSystem>();
this.Shoot();
}
void OnCollisionEnter(Collision collision)
{
Debug.LogFormat("OnCollisionEnter: {0}", collision.gameObject.name);
this.rbody.isKinematic = true;
this.particle.Play();
}
public void Shoot()
{
this.rbody.AddForce(-direct*2000); // 밤송이 위치에 따라 조절해주기
}
}
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class BamsongiGenerator : MonoBehaviour
{
[SerializeField] GameObject bamsngiprefab;
void Update()
{
//화면을 터치하면 밤송이 생성
if (Input.GetMouseButtonDown(0))
{
Debug.Log(Input.mousePosition);
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Debug.Log(ray);
Vector3 direct = Vector3.Normalize(ray.direction);
GameObject Go = Instantiate(this.bamsngiprefab);
Go.GetComponent<BamsongiController>().direct = -direct; //밤송이가 날아가는 방향에 따라 조절해주기
}
}
}
밤송이 벡터 위치가 이상해서 위치 잡느라 힘들었다 ㅠㅠㅠㅠ
밤송이가 막 과녁방향이 아니고 카메라쪽으로 날아오고 난리

'게임개발 > 게임 클라이언트 프로그래밍' 카테고리의 다른 글
ShootingSpace (2) 적과 총알의 충돌 (0) | 2024.02.03 |
---|---|
ShootingSpace(1) 우주선 총알 발사 (0) | 2024.02.03 |
PirateBomb (2) Captain (0) | 2024.02.01 |
PirateBomb(1) BombGuy (0) | 2024.02.01 |
Cat Climb Cloud (1) | 2024.01.31 |