记录几个实用的unity动态效果

一、物体绕中心轴转动

using UnityEngine;
using System.Collections;
public class Axis_rotator : MonoBehaviour {
	 public float Yspeed =0;
	 public float Xspeed =0;
	 public float Zspeed = 0;
	 private float xf;
	 private float yf;
	 private float zf;
	 void Update () {
	  yf += Yspeed * Time.deltaTime;
	  xf += Xspeed * Time.deltaTime; 
	  zf += Zspeed * Time.deltaTime; 
	  transform.localEulerAngles = new Vector3 (xf, yf, zf);
	}
}

二、物体像心脏跳动一样收缩放大。

using UnityEngine;
using System.Collections;
public class LocalScalePulse : MonoBehaviour {
 public float pulseSpeed = 1;
 public float MaxScale = 1;
 private float scaleL;
 void Update () {
  scaleL = 1 + Mathf.PingPong (Time.time * pulseSpeed , MaxScale);
  transform.localScale = new Vector3 (scaleL, scaleL, scaleL);
 }
}

三、物体表面纹理滚动

using UnityEngine;
using System.Collections;
public class Panner : MonoBehaviour {
 public Renderer PanMat;
 public float Uspeed;
 public float Vspeed;
 private float uP;
 private float vP;
 private float Ttt;
 void Update ()
 {  
  uP = Uspeed * Time.time;
  vP = Vspeed * Time.time; 
  PanMat.material.mainTextureOffset = new Vector2 (uP, vP);   
 }
}

四、物体表面颜色像弥红灯一样变化。

sing UnityEngine;
using System.Collections;
public class TextureSwitcher : MonoBehaviour {
 public Texture[] Textures;
 public Renderer TargetRendererMesh;
 public Color[] TexturesColors;
 public float MaxTime = 10;
 public float MinTime = 5;
 private float FinTime;
 private Color FinColor;
 // Use this for initialization
 void Start () {
  TextureSwitch (); 
 } 
 // Update is called once per frame
 void Update () {
  FinTime -= Time.deltaTime;
  if (FinTime < 0.0f)
  {
   TextureSwitch ();
  } 
 }
 void TextureSwitch()
 {
  FinColor = TexturesColors[Random.Range(0,TexturesColors.Length)];
  TargetRendererMesh.material.mainTexture = Textures[Random.Range(0,Textures.Length)];
  TargetRendererMesh.material.SetColor ("_TintColor", FinColor);
  FinTime = Random.Range (MinTime, MaxTime);
 }
}

五、灯光闪烁。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class badLamp : MonoBehaviour
{
    private float shake;
    //private MeshRenderer lamp;
    private Light lamp;         
    // Start is called before the first frame update
    void Start()
    {
        lamp = gameObject.GetComponent<Light>();        
    }
        // Update is called once per frame
    void Update()
    {
        shake += Time.deltaTime;
        if (shake % 1 > 0.5f)
        {
            lamp.enabled = true;
        }
        else
        {
            lamp.enabled = false;
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值