unity 物体震动
using System.Collections; using System.Collections.Generic; using UnityEngine; public class ShaiFenJi : MonoBehaviour { public GameObject wuTi;//物体 private C_Model model; Vector3 first_pos; private float swing = 0.02f;//震动幅度 // Use this for initialization void Start () { model = this.GetComponent<C_Model>(); first_pos = wuTi.transform.localPosition; } // Update is called once per frame void Update () { if (model.Info ==1) { Vector3 pos = first_pos + Random.insideUnitSphere * swing; pos.y = wuTi.transform.localPosition.y; wuTi.transform.localPosition = pos; } } }
亲测可用 ! ! !