Unity 19.4.15 Zenject 9.8 CS1513:但已经全部关闭 Functions/Class
Unity 19.4.15 Zenject 9.8 CS1513: But Already Closed All Functions/Class
[已编辑]
移动 [注入] 标签不起作用 //<-- 因为是 [注入]
现在有两个错误:
Assets\player\playercontroller\armory\rifle.cs(10,10):错误 CS0246:找不到类型或命名空间名称 'injectAttribute'(是否缺少 using 指令或程序集引用?)
Assets\player\playercontroller\armory\rifle.cs(10,10):错误 CS0246:找不到类型或命名空间名称 'inject'(是否缺少 using 指令或程序集引用?)
新代码在这里。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Zenject;
namespace zenject.injection
{
public class InjectObject
{
[inject] //<is [Inject],fu
GameObject RifleMuzzle;
}
public class rifle : Weapon
{
// Start is called before the first frame update
private float cooldownTime = 0f;
private float mag = 5;
private int magSize = 5;
public void Rifle()
{
}
public void Cooldown( float time )
{
cooldownTime -= time;
}
public void Fire()
{
if ( cooldownTime <= 0f && mag>0)
{
RayCast.GetRay();
RayCast.GetRay(Muzzle.transform.position,Vector3.forward,0f);
cooldownTime = 0.1f;
mag = mag - 1;
if (mag == 0)
{
reload();
}
}
}
public void reload()
{
mag = magSize;
}
}
}
在开始之前,我不得不感谢大家帮我解决问题
我已经看过了 Getting CS1513 } Expected, but all braces are there
但它不起作用。
这是我的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class rifle : Weapon
{
// Start is called before the first frame update
private float cooldownTime = 0f;
private float mag = 5;
private int magSize = 5;
private GameObject Muzzle = GameObject.Find("RifleMuzzle"); //I tried to deleted this,not working T_T
public void Awake()
{ //<-- Assets\player\playercontroller\armory\rifle.cs(13,6): error CS1513: } expected
[inject]
Gameobject RifleMuzzle;
} //<-- What complier asked for.
public void Cooldown( float time )
{
cooldownTime -= time;
}
public void Fire()
{
if ( cooldownTime <= 0f && mag>0)
{
RayCast.GetRay();
RayCast.GetRay(Muzzle.transform.position,Vector3.forward,0f);
cooldownTime = 0.1f;
mag = mag - 1;
if (mag == 0)
{
reload();
}
}
}
public void reload()
{
mag = magSize;
}
} //<-- Assets\player\playercontroller\armory\rifle.cs(47,1): error CS1022: Type or namespace definition, or end-of-file expected
//If I delete line 13,it'll disappared.
只允许
- 构造函数
- 方法
- 参数
- 字段
- 属性
对于你的局部变量 RifleMuzzle
在Awake
里面是不合适的(实际上是no attribute is)。因此,编译器简单地假设您想要在引入具有 [Inject]
属性的 class field RifleMuzzle
之前关闭 Awake
方法。
应该是
[Inject]
private GameObject Muzzle; //or RifleMuzzle
private void Awake()
{
// Wouldn't be needed if empty anyway
}
[已编辑]
移动 [注入] 标签不起作用 //<-- 因为是 [注入]
现在有两个错误:
Assets\player\playercontroller\armory\rifle.cs(10,10):错误 CS0246:找不到类型或命名空间名称 'injectAttribute'(是否缺少 using 指令或程序集引用?)
Assets\player\playercontroller\armory\rifle.cs(10,10):错误 CS0246:找不到类型或命名空间名称 'inject'(是否缺少 using 指令或程序集引用?)
新代码在这里。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Zenject;
namespace zenject.injection
{
public class InjectObject
{
[inject] //<is [Inject],fu
GameObject RifleMuzzle;
}
public class rifle : Weapon
{
// Start is called before the first frame update
private float cooldownTime = 0f;
private float mag = 5;
private int magSize = 5;
public void Rifle()
{
}
public void Cooldown( float time )
{
cooldownTime -= time;
}
public void Fire()
{
if ( cooldownTime <= 0f && mag>0)
{
RayCast.GetRay();
RayCast.GetRay(Muzzle.transform.position,Vector3.forward,0f);
cooldownTime = 0.1f;
mag = mag - 1;
if (mag == 0)
{
reload();
}
}
}
public void reload()
{
mag = magSize;
}
}
}
在开始之前,我不得不感谢大家帮我解决问题
我已经看过了 Getting CS1513 } Expected, but all braces are there 但它不起作用。
这是我的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class rifle : Weapon
{
// Start is called before the first frame update
private float cooldownTime = 0f;
private float mag = 5;
private int magSize = 5;
private GameObject Muzzle = GameObject.Find("RifleMuzzle"); //I tried to deleted this,not working T_T
public void Awake()
{ //<-- Assets\player\playercontroller\armory\rifle.cs(13,6): error CS1513: } expected
[inject]
Gameobject RifleMuzzle;
} //<-- What complier asked for.
public void Cooldown( float time )
{
cooldownTime -= time;
}
public void Fire()
{
if ( cooldownTime <= 0f && mag>0)
{
RayCast.GetRay();
RayCast.GetRay(Muzzle.transform.position,Vector3.forward,0f);
cooldownTime = 0.1f;
mag = mag - 1;
if (mag == 0)
{
reload();
}
}
}
public void reload()
{
mag = magSize;
}
} //<-- Assets\player\playercontroller\armory\rifle.cs(47,1): error CS1022: Type or namespace definition, or end-of-file expected
//If I delete line 13,it'll disappared.
只允许
- 构造函数
- 方法
- 参数
- 字段
- 属性
对于你的局部变量 RifleMuzzle
在Awake
里面是不合适的(实际上是no attribute is)。因此,编译器简单地假设您想要在引入具有 [Inject]
属性的 class field RifleMuzzle
之前关闭 Awake
方法。
应该是
[Inject]
private GameObject Muzzle; //or RifleMuzzle
private void Awake()
{
// Wouldn't be needed if empty anyway
}