javascript - 将 js 翻译为 C#

标签 javascript c# unity-game-engine

需要将 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 <', expectingidentifier'

有什么想法可以解决这个问题吗?

最佳答案

只需删除 GetComponent.<Renderer> 中的点即可 => GetComponent<Renderer>

关于javascript - 将 js 翻译为 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39006052/

相关文章:

javascript - 为什么 ApplicationRoute 对转换没有反应

c# - 使用C#隐藏任务栏

unity-game-engine - 将 GLSL Shadertoy 着色器移植到 Unity 时出现问题

javascript - 如何获取canvas的中心点

javascript - 如何在 react 中显示动态状态

c# - Java 与 C# Web 服务客户端

c# - 如何以Xamarin形式显示gif图像?

c# - 字符串长度不等于字符串数据 Unity C#

unity-game-engine - unity Json.net bson 自引用循环

javascript - 当我的配置文件中有一个普通数组时,我应该如何使用 jQuery extend?