using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Unity.VisualScripting;
using UnityEngine;
public class BamsongiController : MonoBehaviour
{
private Rigidbody rb;
private ParticleSystem particleSystem;
void Start()
{
this.particleSystem = this.GetComponent<ParticleSystem>();
this.rb = GetComponent<Rigidbody>();
Shoot();
}
// Update is called once per frame
void Update()
{
}
private void OnCollisionEnter(Collision collision)
{
Debug.LogFormat("OnCollisionEnter: {0}", collision.gameObject.name);
this.rb.isKinematic = true;
this.particleSystem.Play();
}
private void Shoot()
{
this.rb.AddForce(new Vector3(0, 200, -2000));
}
}
2. BamsongiController.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BamsongiGenerator : MonoBehaviour
{
[SerializeField] private GameObject bamsongiGo;
public float spawnDistance = 5f; // 카메라로부터의 생성 거리
void Update()
{
// 마우스 왼쪽 버튼 클릭을 감지
if (Input.GetMouseButtonDown(0))
{
// 마우스 클릭 위치를 월드 좌표로 변환
Vector3 spawnPosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, spawnDistance));
// 프리팹을 spawnPosition 위치에 생성
GameObject spawnedObject = Instantiate(bamsongiGo, spawnPosition, Quaternion.identity);
}
}
}
3. BamsongiGenerator.cs
반응형
'산대특 > 게임 클라이언트 프로그래밍' 카테고리의 다른 글
[PirateBomb] 캐릭터의 이동과 공격, 적의 피격과 사망 (0) | 2024.02.05 |
---|---|
[SpaceShooter2D] 비행기[Player] GetAxis로 이동하기 + 정규화(Normalize) (0) | 2024.02.02 |
Update와 Coroutine (0) | 2024.02.02 |
[ClimbCloud] 캐릭터를 AddForce로 이동 및 좌우 전환 만들어보기 (0) | 2024.01.31 |
[CatEscape] CatEscape 만들기 (0) | 2024.01.29 |