Net.Like.Xue.Tokyo/Assets/Artists/Scripts/ReplaceModel.cs

36 lines
922 B
C#
Raw Normal View History

2025-04-18 20:27:57 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using Dreamteck.Splines.Primitives;
using UnityEngine;
using Object = System.Object;
using Random = UnityEngine.Random;
namespace Net.Like.Xue.Tokyo
{
public class ReplaceModel : MonoBehaviour
{
[SerializeField] private Animator animator;
[SerializeField] private Transform[] models;
private void Start()
{
for (var i = 0; i < transform.childCount; i++)
{
DestroyImmediate(transform.GetChild(0));
}
var index = Random.Range(0, transform.childCount);
var newModel =models[index];
newModel = Instantiate(newModel, transform);
if (newModel.TryGetComponent<Animator>(out var x))
{
DestroyImmediate(x);
}
animator.Rebind();
}
}
}