ScriptableObject

조창일·2024년 6월 18일

내배캠

목록 보기
44/51
post-thumbnail
[CreateAssetMenu]

public class Cars : ScriptableObject
{
    public GameObject[] car;
    public float moveSpeed;
    public float rangeDestroy;
}

스크립트블 오브젝트 선언

값 넣어주기

public class Car : MonoBehaviour
{
    public Cars cars;

    void Update()
    {
        float moveX = cars.moveSpeed * Time.deltaTime;
        transform.Translate(moveX, 0f, 0f);

        if (transform.localPosition.x >= cars.rangeDestroy)
        {
            Destroy(gameObject);
        }
    }

차 스크립트에 불러와주기

    private void CloneCar()
    {
        Transform transform = PrefabTransform;
        Vector3 height = transform.position;
        height.y = 1f;

        int randomCar = Random.Range(0, cars.car.Length);

        GameObject cloneoObj = Instantiate(cars.car[randomCar], height, PrefabTransform.rotation, this.transform);

        cloneoObj.SetActive(true);
    }

차 생성에 불러와주기

profile
안녕하세요.

0개의 댓글