码迷,mamicode.com
首页 > 编程语言 > 详细

Unity 实现图片抖动

时间:2019-12-10 17:14:27      阅读:310      评论:0      收藏:0      [点我收藏+]

标签:gre   class   实现   using   add   抖动   cal   gety   code   

 1 using UnityEngine;
 2 using System.Collections;
 3 //物体抖动
 4 public class ObjectShake : MonoBehaviour {
 5     
 6     public bool isEnable=true;
 7     public Vector3 shakedegree=Vector3.one*0.1f;
 8     public float addDegreeTime=2;
 9     
10     private Vector3 originPosition;
11     private float timeCount;
12     
13     void Start()
14     {
15         originPosition=transform.localPosition;
16     }
17     
18     void Update()
19     {
20         if(isEnable)
21         {
22             if(timeCount<addDegreeTime)
23                 timeCount+=Time.deltaTime;
24             else
25                 timeCount=addDegreeTime;
26             transform.localPosition=new Vector3(GetX(),GetY(),GetZ());
27         }
28         else
29         {
30             if(timeCount>0)
31             {
32                 timeCount-=Time.deltaTime;
33                 transform.localPosition=new Vector3(GetX(),GetY(),GetZ());
34             }
35             else
36             {
37                 transform.localPosition=originPosition;
38             }
39         }
40     }
41     
42     private float GetX()
43     {
44         return originPosition.x+Random.Range(-1*timeCount*shakedegree.x,timeCount*shakedegree.x);
45     }
46     private float GetY()
47     {
48         return originPosition.y+Random.Range(-1*timeCount*shakedegree.y,timeCount*shakedegree.y);
49     }
50     private float GetZ()
51     {
52         return originPosition.z+Random.Range(-1*timeCount*shakedegree.y,timeCount*shakedegree.y);
53     }
54 }

 

Unity 实现图片抖动

标签:gre   class   实现   using   add   抖动   cal   gety   code   

原文地址:https://www.cnblogs.com/DGJS/p/12017394.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!