using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class AnimationController : MonoBehaviour

{

    public AnimationClip animationClip; // 재생할 애니메이션 클립

    public float animationDuration = 2.0f; // 애니메이션 재생 시간(초)


    private Animation animationComponent;

    private bool animationPlaying = false;


    private void Start()

    {

        animationComponent = GetComponent<Animation>();


        // AnimationClip이 지정되지 않은 경우 기본적으로 연결된 Animation 컴포넌트의 첫 번째 애니메이션을 사용합니다.

        if (animationClip == null && animationComponent != null && animationComponent.clip != null)

        {

            animationClip = animationComponent.clip;

        }

    }


    private void Update()

    {

        // 마우스 왼쪽 버튼이 눌리면

        if (Input.GetMouseButtonDown(0))

        {

            // 클릭한 위치를 가져옵니다.

            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            RaycastHit hit;


            if (Physics.Raycast(ray, out hit))

            {

                // 클릭한 위치에 애니메이션을 재생합니다.

                PlayAnimation(hit.point);

            }

        }


        // 애니메이션이 재생 중이고 지정된 시간이 경과하면

        if (animationPlaying && Time.time >= animationDuration)

        {

            // 애니메이션을 제거합니다.

            DestroyAnimation();

        }

    }


    // 지정된 위치에 애니메이션을 재생하는 함수

    private void PlayAnimation(Vector3 position)

    {

        if (animationClip != null)

        {

            // 애니메이션을 재생할 위치에 개체를 생성합니다.

            GameObject animObject = new GameObject("AnimationObject");

            animObject.transform.position = position;


            // 개체에 Animation 컴포넌트를 추가하고 지정된 애니메이션을 재생합니다.

            Animation anim = animObject.AddComponent<Animation>();

            anim.AddClip(animationClip, "CustomAnimation");

            anim.Play("CustomAnimation");


            // 애니메이션 재생 중 플래그를 설정합니다.

            animationPlaying = true;

        }

    }


    // 애니메이션을 제거하는 함수

    private void DestroyAnimation()

    {

        animationPlaying = false;

        Destroy(GameObject.Find("AnimationObject"));

    }

}






아무데나 클릭하면 애니메이션을 재생하고 없애는 코딩.... 인거같은데 맞음?

왜 애니메이션이 안나오는거지ㅠㅠㅠㅠㅠㅠㅠ 

참고로 나 문과에 프로그래밍은 챗지피티한테 맡기고있음 영어도 잘 못함 ㅠㅠㅠㅠㅠㅠ