ShanxiKnowledgeBase/SXElectricalInspection/Assets/Adam/Scripts/Components/LadderCtr.cs

64 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//============================================================
//支持中文文件使用UTF-8编码
//@author Adam
//@create 20240607
//@company Adam
//
//@description:
//============================================================
namespace Components
{
public class LadderCtr : MonoBehaviour
{
private SkinnedMeshRenderer smr;
public List<GameObject> ladders = new List<GameObject>();
public float minValue = 0f;
public float maxValue = 100f;
public float t = 0.08f;
public float interpolatedValue;
public bool isPlay = false;
// Use this for initialization
public Transform playerPos;
public void SwitchLadder(string ladderName)
{
if (ladderName != "")
{
gameObject.SetActive(true);
isPlay = true;
GameObject ladder = null;
for (int i = 0; i < ladders.Count; i++)
{
int index = i;
ladders[index].SetActive(false);
if (ladders[index].name.Equals(ladderName))
{
ladders[index].SetActive(true);
ladder = ladders[index];
}
}
smr = ladder.GetComponentInChildren<SkinnedMeshRenderer>();
}
else
{
isPlay = false;
smr.SetBlendShapeWeight(0, 0);
gameObject.SetActive(false);
}
}
private void Update()
{
if (!isPlay) return;
interpolatedValue = Mathf.Lerp(interpolatedValue, maxValue, t);
smr.SetBlendShapeWeight(0, interpolatedValue);
if (interpolatedValue > (maxValue - 8f))
{
isPlay = false;
}
}
}
}