using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BamsongiController : MonoBehaviour
{
private Rigidbody rBody;
private ParticleSystem fx;
// Start is called before the first frame update
private void Awake()
{
this.rBody = this.GetComponent<Rigidbody>();
//this.Shoot(new Vector3(0, 200, 2000));
this.fx = this.GetComponent<ParticleSystem>();
}
void Start()
{
}
public void Shoot(Vector3 force)
{
this.rBody.AddForce(force);
}
private void OnCollisionEnter(Collision collision)
{
this.rBody.isKinematic = true;
this.fx.Play();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BamsongiGenerator : MonoBehaviour
{
public GameObject prefab;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
var go = Instantiate(this.prefab);
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
go.transform.position = ray.origin+ new Vector3(0, 0, 2);
var dir = ray.direction.normalized; //길이가 1인 방향 백터(노멀 백터)
go.GetComponent<BamsongiController>().Shoot(dir * 2000);
}
}
}