统一编程C#
无法确定我应该为以下错误执行什么操作: 赋值的左侧必须是变量、属性或索引器 我是编程新手,如果有人能帮助我,我将不胜感激 多谢各位统一编程C#,c#,unity3d,C#,Unity3d,无法确定我应该为以下错误执行什么操作: 赋值的左侧必须是变量、属性或索引器 我是编程新手,如果有人能帮助我,我将不胜感激 多谢各位 using UnityEngine; using System.Collections; public class ShootingExample : MonoBehaviour { public GameObject projectile; public Transform spawnPoint; public SoundObject f
using UnityEngine;
using System.Collections;
public class ShootingExample : MonoBehaviour {
public GameObject projectile;
public Transform spawnPoint;
public SoundObject fightSound = new SoundObject();
public SoundObject hitSound = new SoundObject();
public Transform gun;
public Transform ammo;
public bool calculationDamage = false; //2011-05-26
private Transform myTargetPoint; //2011-05-26
// Use this for initialization
void Awake () {
fightSound.gameObject = gameObject;
fightSound.Init();
hitSound.gameObject = gameObject;
hitSound.Init();
//2011-05-26 -B
if (GetComponentInChildren<TargetPointBehaviour>() != null)
{
TargetPointBehaviour tpScript = GetComponentInChildren<TargetPointBehaviour>();
myTargetPoint = tpScript.gameObject.transform;
}
//2011-05-26 -E
}
// Update is called once per frame
void Update () {
//2011-05-26 -B
//if (Input.GetButtonDown("Fire1"))
//{
// StartCoroutine(Shoot());
//}
if (calculationDamage)
{
gun.gameObject.SetActive = false;
ammo.gameObject.SetActive = false;
if (Input.GetButtonDown("Fire1"))
{
StartCoroutine(Hit());
}
}
else
{
gun.gameObject.SetActive = true;
ammo.gameObject.SetActive = true;
if (Input.GetButtonDown("Fire1"))
{
StartCoroutine(Shoot());
}
}
//2011-05-26 -E
}
IEnumerator Shoot()
{
GameObject proj;
yield return new WaitForSeconds(0.4f);
proj = (GameObject)Instantiate(projectile, spawnPoint.position, spawnPoint.rotation);
fightSound.Play();
proj.GetComponent<Rigidbody>().AddRelativeForce(Vector3.forward * 1000);
}
//2011-05-26 -B
IEnumerator Hit()
{
RaycastHit hit;
yield return new WaitForSeconds(0.2f);
hitSound.Play();
if (Physics.Raycast(myTargetPoint.position, myTargetPoint.TransformDirection(Vector3.forward), out hit, 1.5f))
{
hit.transform.gameObject.SendMessage("ApplyDamage", 10, SendMessageOptions.DontRequireReceiver);
}
}
void OnGUI()
{
GUILayout.Space(40);
calculationDamage = GUILayout.Toggle(calculationDamage, "Beating (Calculation Damage)");
}
//2011-05-26 -E
}
使用UnityEngine;
使用系统集合;
公共课射击示例:单行为{
公共游戏对象投射物;
公共转换点;
public SoundObject fightSound=新建SoundObject();
public SoundObject hitSound=新的SoundObject();
公共转换枪;
公共弹药;
公共布尔计算损害=false;//2011-05-26
私有转换myTargetPoint;//2011-05-26
//用于初始化
无效唤醒(){
fightSound.gameObject=游戏对象;
fightSound.Init();
hitSound.gameObject=游戏对象;
hitSound.Init();
//2011-05-26-B
if(getComponentChildren()!=null)
{
targetPointBehavior tpScript=GetComponentChildren();
myTargetPoint=tpScript.gameObject.transform;
}
//2011-05-26-E
}
//每帧调用一次更新
无效更新(){
//2011-05-26-B
//if(Input.GetButtonDown(“Fire1”))
//{
//开始例行程序(Shoot());
//}
如果(计算损坏)
{
gun.gameObject.SetActive=false;
ammo.gameObject.SetActive=false;
if(Input.GetButtonDown(“Fire1”))
{
start例程(Hit());
}
}
其他的
{
gun.gameObject.SetActive=true;
ammo.gameObject.SetActive=true;
if(Input.GetButtonDown(“Fire1”))
{
开始例行程序(Shoot());
}
}
//2011-05-26-E
}
IEnumerator Shoot()
{
游戏对象项目;
收益率返回新WaitForSeconds(0.4f);
proj=(游戏对象)实例化(投射物,spawnPoint.position,spawnPoint.rotation);
打斗声。播放();
proj.GetComponent().AddRelativeForce(Vector3.forward*1000);
}
//2011-05-26-B
IEnumerator Hit()
{
雷卡斯特击中;
收益率返回新WaitForSeconds(0.2f);
hitSound.Play();
if(物理光线投射(myTargetPoint.position,myTargetPoint.TransformDirection(矢量3.forward),命中率1.5f))
{
hit.transform.gameObject.SendMessage(“ApplyDamage”,10,SendMessageOptions.DontRequestReceiver);
}
}
void OnGUI()
{
空间(40);
计算伤害=GUILayout.Toggle(计算伤害,“殴打(计算伤害)”);
}
//2011-05-26-E
}
这样的行有4行:
gun.gameObject.SetActive = false;
gun.gameObject.SetActive(false);
您正在尝试将值false
分配给它。正如错误所说,只有当它是一个属性(或变量或索引器)时,才能这样做SetActive
是一种获取参数的方法,如下所示:
gun.gameObject.SetActive = false;
gun.gameObject.SetActive(false);
命令式“SetActive”表示它是一种方法。属性通常被称为“IsActive”或只是“Active”。有以下4行:
gun.gameObject.SetActive = false;
gun.gameObject.SetActive(false);
您正在尝试将值false
分配给它。正如错误所说,只有当它是一个属性(或变量或索引器)时,才能这样做SetActive
是一种获取参数的方法,如下所示:
gun.gameObject.SetActive = false;
gun.gameObject.SetActive(false);
命令式“SetActive”表示它是一种方法。属性通常被称为“IsActive”或只是“Active”。有以下4行:
gun.gameObject.SetActive = false;
gun.gameObject.SetActive(false);
您正在尝试将值false
分配给它。正如错误所说,只有当它是一个属性(或变量或索引器)时,才能这样做SetActive
是一种获取参数的方法,如下所示:
gun.gameObject.SetActive = false;
gun.gameObject.SetActive(false);
命令式“SetActive”表示它是一种方法。属性通常被称为“IsActive”或只是“Active”。有以下4行:
gun.gameObject.SetActive = false;
gun.gameObject.SetActive(false);
您正在尝试将值false
分配给它。正如错误所说,只有当它是一个属性(或变量或索引器)时,才能这样做SetActive
是一种获取参数的方法,如下所示:
gun.gameObject.SetActive = false;
gun.gameObject.SetActive(false);
命令式“SetActive”表示它是一种方法。一个属性通常被称为“ISActive”或“激活”。哪一行引起错误?考虑在标题中更具体。错误就是它所说的。找到有问题的那一行并修复它-几乎所有发布的代码都不相关。它的第40、41、49、50行,我不明白我应该做什么fix@brownmamba71-您需要提供有关您正在使用的库的更多信息?我猜你指的是“unturn.Rok.4.Fase4.2.0.1”,因为有统一的框架可用。还提到你得到哪一行错误。哪一行导致错误?考虑在标题中更具体。错误就是它所说的。找到有问题的那一行并修复它-几乎所有发布的代码都不相关。它的第40、41、49、50行,我不明白我应该做什么fix@brownmamba71-您需要提供有关您正在使用的库的更多信息?我猜你指的是“unturn.Rok.4.Fase4.2.0.1”,因为有统一的框架可用。还提到你得到哪一行错误。哪一行导致错误?考虑在标题中更具体。错误就是它所说的。找到有问题的那一行并修复它-几乎所有发布的代码都不相关。它的第40、41、49、50行,我不明白我应该做什么fix@brownmamba71-您需要提供有关您正在使用的库的更多信息?我猜你指的是“unturn.Rok.4.Fase4.2.0.1”,因为有统一的框架可用。还提到你得到哪一行错误。哪一行导致错误?考虑在标题中更具体。错误就是它所说的。快走