一、物体绕中心轴转动
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;
}
}
}