一个物体从A点到B点,持续运行,当物体从A点到达B点的过程中逐渐变小,并停止运动
public GameObject mycube;
float speed = 0.1f;//移动速度
float speed_s = 0.01f;//缩放速度
void Update()
{
mycube.transform.position += new Vector3(speed,0,0);
//控制mycube的向前位移
if(mycube.transform.position.x >= 10.0)//判定物体达到一个位置
{
mycube.transform.localScale -= new Vector3(speed_s,speed_s,speed_s);
//物体开始以0.01的速度缩小
if(transform.localScale.x <= 0.5f && transform.localScale.y <= 0.5f && transform.localScale.z <= 0.5f)
//如果缩小到0.5的时候
{
speed_s = 0;//缩放的速度等于0,此时中断缩小速度
speed = 0;//同时中断移动速度
}
}
}
边走边小,中途变色
public GameObject mycube;
void Update()
{
if(mycube.transform.position.x <= 7)
{
mycube.transform.position += new Vector(0.03f,0,0);//以0.03的速度移动
if(mycube.transform.position.x >=3)
{
mycube.GetComponent
mycube.transform.localScale = new Vector3(1f,1f,1f);//物体大小
}
if(mycube.transform.position.x >= 7)
{
mycube.transform.localScale = new Vector(0.5f,0.5f,0.5f);
}
}
}
物体小到一定程度逐渐恢复原状
public GameObject mycube;
float speed = 0.2f;
flaot speed_s = 0.001f;
void Update()
{
mycube.transform.Rotate(speed,0,0);//物体自身旋转
if(mycube.transform.eulerAngles.x >= 20)
{
mycube.transform.localScale -= new Vector3(speed_s,speed_s,speed_s);//物体缩小
if(mycube.transform.localScale.x <= 0.5f && mycube.transform.localScale.y <= 0.5f && mycube.transform.localScale.z <=0.5f)
{
speed_s = -0.001f;//物体放大
}
if(mycube.transform.localScale.x >= 1f && mycube.transform.localScale.y >= 1f && mycube.transform.localScale.z >=1f)
{
speed = 0f;
speed_s = 0f;
}
}
}
物体循环变大变小
public GameObject mycube;
float speed = 0.2f;//自身旋转速度
float speed_s = 0.01f;//缩放速度
void Update()
{
mycube.transform.Rotate(speed,0,0);
if(mycube.transform.eulerAngles.x >= 20)
{
mycube.transform.localScale -= new Vector3(speed_s,speed_s,speed_s);
if(mycube.transform.localScale.x <= 0.5f && mycube.transform.localScale.y <=0.5f && mycube.transform.localScale.z <= 0.5f)
{
speed_s = -0.01f;
}
if(mycube.transform.localScale.x >= 1f && mycube.transform.localScale.y >=1f && mycube.transform.localScale.z >= 1f)
{
speed_s = 0.01f;
}
}
}