using UnityEngine;
using System.Collections;
public class controller : MonoBehaviour {
public float MaxSpeedObj = 5.0f;
public bool AxisIsRightLeft = true;//always true unless you create it
//private Animator anim;
public void FilpObject () {
AxisIsRightLeft = !AxisIsRightLeft;
Vector3 objectScale = transform.localScale;
objectScale.x *= -1;
transform.localScale = objectScale;
}
void Start () {
//anim = GetComponent<Animator>();
}
void Update () {
float dirction = Input.GetAxis("Horizontal");
//anim.SetFloat("speed", Mathf.Abs( MaxSpeedObj * dirction ));
if (dirction > 0 && AxisIsRightLeft == !true)
FilpObject();
else if (dirction < 0 && AxisIsRightLeft == !false)
FilpObject();
}
}这一段代码中我想使物体的scale值乘上-1得到反方向应此写了一个方法名为filpobject,最后通过getAxis判断键盘方向来判断反方向。代码都没问题,键盘向左箭头摁物体也随着变化,scale值的确乘上了-1。问题是,scale值变了之后其进行了位移!?触发代码后:postion没有变啊?怎么就位移了?
- 2 回答
- 0 关注
- 1682 浏览
添加回答
举报
0/150
提交
取消