大家好,我的游戏有问题,这个问题是基于我切换材料的时候,所以它可以面向另一个方向(这是一个 2d 游戏)。这会影响由 renderer.material.mainTextureOffset 控制的动画,但我不知道为什么这不起作用。
c#中的代码:
using UnityEngine;
using System.Collections;
public class character : MonoBehaviour {
public float forwardSpeed = 10.0f;
public Material newMaterialRefcs1;
public Material newMaterialRefcs2;
// Use this for initialization
void Start () {
}
//error is occurring here !!!!!!!! below Important. The 2 if statements below
// Update is called once per frame
void Update () {
if( Input.GetKey(KeyCode.D)){
renderer.material.mainTextureOffset = new Vector2(0.25f, 0);
transform.position += -transform.right * forwardSpeed * Time.deltaTime;
renderer.material = newMaterialRefcs1;
}if( Input.GetKey(KeyCode.A)){
renderer.material.mainTextureOffset = new Vector2(0.25f, 0);
transform.position += transform.right * forwardSpeed * Time.deltaTime;
renderer.material = newMaterialRefcs2;
}
}}