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);

            
        }
    }
}

'C# > 수업 내용' 카테고리의 다른 글

미사키 움직이기  (0) 2023.02.02
230201  (0) 2023.02.01
메카님 연습 Cs  (0) 2023.02.01
230131  (0) 2023.01.31
BFS  (0) 2023.01.30

+ Recent posts