[编辑]
移动 [inject] 标签不起作用 //<--因为是 [Inject]
现在它有两个错误:
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 } 预期的,但所有 的大括号都在那里但它不起作用。
这是我的代码:
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.