unity和vs问题新手小白求大佬指点迷津
unity3d吧
全部回复
仅看楼主
level 1
就是一个按键使角色移动变色的程序
2023年09月20日 16点09分 1
level 1
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObjectController : MonoBehaviour
{
public float moveSpeed = 5f;
public Color[] colors;
private int currentColorIndex = 0;
private void Update()
{
// 移动物体
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
transform.Translate(new Vector3(moveHorizontal, moveVertical, 0) * moveSpeed * Time.deltaTime);
// 更改物体颜色
if (Input.GetKeyDown(KeyCode.Space))
{
ChangeColor();
}
}
private void ChangeColor()
{
Renderer renderer = GetComponent<Renderer>();
// 切换到下一个颜色
currentColorIndex = (currentColorIndex + 1) % colors.Length;
// 设置新颜色
网页链接 = colors[currentColorIndex];
}
}
2023年09月20日 16点09分 2
这是程序部分那个网址的上面图片有麻烦了
2023年09月20日 16点09分
level 11
你脚本名里面和外面命名不一致,先修改成一样的了
2023年09月21日 01点09分 3
level 1
类名和脚本文件名不一致
2023年09月21日 03点09分 4
1