需要将 JS 转换为 C# 的帮助。
原始脚本:
var target : GameObject;
var fadeDuration : float = 3.0;
function Update(){
if (target.GetComponent.<Renderer>().material.color.a > 0)
target.GetComponent.<Renderer>().material.color.a -= Time.deltaTime/fadeDuration;
}
翻译后的 C# 脚本:
using UnityEngine;
using System.Collections;
public class FadeOutDeadBody : MonoBehaviour {
GameObject target;
float fadeDuration = 3.0f;
void Update (){
if (target.GetComponent.<Renderer>().material.color.a > 0)
target.GetComponent.<Renderer>().material.color.a -= Time.deltaTime/fadeDuration;
}
}
我收到来自 Unity3d 的错误:
folder/FadeOutDeadBody.cs(9,29): error CS1525: Unexpected symbol
<', expecting
identifier'
有什么想法可以解决这个问题吗?
最佳答案
只需删除 GetComponent.<Renderer>
中的点即可
=> GetComponent<Renderer>
关于javascript - 将 js 翻译为 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39006052/