我试图理解我的团结项目的继承,但似乎已经找到了我的设置的限制.在写作的过程中,我感到很困惑,因为我仍在学习正确理解C#.
我有一组继承的类,它们基于两种不同的行为进行拆分,这样我就有了正确的引用.
然后我需要转换它们,以便我可以访问其中一个类中的方法.所以我的结构看起来像这样:
public class Behaviour : Position {
public Handler reference;
public Behaviour(int tx, int ty, Handler refer) : base (tx,ty){
reference = refer;
}
// overload
public Behaviour(int tx, int ty) : base (tx,ty){}
}
public class Behaviour2 : Position {
public SettingsHandler reference;
public Behaviour2(int tx, int ty, SettingsHandler refer) : base (tx,ty) {
reference = refer;
}
}
public class SettingsHandler : Handler {
public Settings level {get;set;}
}
public class Handler : MonoBehaviour{
virtual public …Run Code Online (Sandbox Code Playgroud) 我试过搜索但是在解释共同例程系统的所有线程之间丢失了但没有详细说明.我已经知道StartCoroutine返回一个Co-routine,所以我试着查看是否有某种隐式运算符重载为void返回类型甚至尝试过,但它没有用,我什么都没发现.老实说我只能想到,你可以说我是初学者这个问题没有具体的目标,我真的很感兴趣.提前致谢
编辑:我不作出清楚我的问题道歉:怎么能说都StartCoroutine(example());和Coroutine myCoroutine = StartCoroutine(example())?如果返回类型是Coroutine,第一个如何像void一样工作?
我有一些物品,一个叫做"父母",一个叫做"儿童"(图中第一个).如何在运行时将"Child"对象作为"Parent"对象的实际子对象(图片中的Nr.2)?

我想在已知的路径中找到该文件,如果它在android中预先存在,则用它触发事件(启用/禁用画布).这是我用过的一个例子 -
public void FileChk(){
string filePath = "file://" + Application.temporaryCachePath + "/" + "folder23" + "/" + fileName;
if (!fileName.Exists)
{
//event
}
else
{
//event
}
}
Run Code Online (Sandbox Code Playgroud)
我在这里做错了什么以及如何在文件存在时触发此事件.
我注意到当我将button的interactable属性设置为false时,按钮alpha减少.有没有人知道如何在Unity中实现这一目标.
myButton.interactable = false;
Run Code Online (Sandbox Code Playgroud)
如果你能提供帮助,那将是非常有帮助的!
谢谢 !
我有以下(相关)代码:
public class GameController : MonoBehaviour {
public class Timer
{
int elapsedTime;
int pausedTime;
bool isCounting;
public void Start()
{
int startTime = DateTime.Now.Millisecond;
while(isCounting)
{
elapsedTime = DateTime.Now.Millisecond - startTime;
}
}
}
private void Update()
{
//Debug logging of the timer functions
if(startButton.CompareTag("Clicked"))
{
Timer.Start();
}
}
Run Code Online (Sandbox Code Playgroud)
}
此代码生成以下错误:非静态字段,方法或属性'GameController.Timer.Start()`需要对象引用.我怎样才能解决这个问题?
(注意:对于几乎每种情况,此错误的原因都不同,因此很难将其称为重复.)
嗨我在c#中进行了新的编码,我正在编写一个脚本来启用/禁用Unity 5游戏对象点击另一个对象进行这两个动作,第一部分运行正常,但在第二部分重新启用对象时显示此错误:
Assets/Script/Activar.cs(11,5):错误CS1519:类,结构或接口成员声明中的意外符号"else"
这是脚本:
using System.Collections;
using UnityEngine;
public class Activar : MonoBehaviour {
public GameObject modify;
void Update () {
if (Input.GetMouseButton (0))
modify.SetActive (false);
}
else {
modify.SetActive (true);
}
}
Run Code Online (Sandbox Code Playgroud)
那么我该怎么做才能解决这个问题呢?谢谢 :)
我很擅长C#和Unity中的脚本.到目前为止,在制作C#(非MB)类时,我会使用以下模式.
public class Item
{
public string itemName;
public Item(string newItemName)
{
itemName = newItemName;
}
}
Run Code Online (Sandbox Code Playgroud)
在其他一些脚本中我可以使用Item rock = new Item("Rock");或其他什么.
现在,我正在使用以下属性.
public class Item
{
string itemName;
public string ItemName
{
get { return itemName; }
set { itemName = value; }
}
}
Run Code Online (Sandbox Code Playgroud)
在我使用的其他一些脚本中 Item rock = new Item(); rock.ItemName = "Rock";
实际上,我经常使用自动实现的属性,并且除了项目的名称之外还有更多的字段.当我使用公共字段时,很容易在构造函数中设置所有这些字段.现在,我不确定如何,或者是否可能(如果我想让它们保密).因此,我发现自己必须使用默认构造函数,然后使用诸如rock.ItemWeight = "1 lb" rock.ItemColor = "gray" rock.ItemType = "blunt instrument"...etc. for every item and field each time a new item is …
我有一个简单的函数,它将bool2个实体之间的距离与GravityRadius字段的比较结果返回值.
public bool IsEntityPulledByGravity(IEntity entity)
{
return Vector3.Distance(State.Position, entity.State.Position) <= GravityRadius;
}
Run Code Online (Sandbox Code Playgroud)
有时它会按照它的设想运行,但有时会返回不正确的false值.我进入调试模式来分析它,我无法弄清楚为什么它会返回false进行比较30 <= 30.我错过了什么?
c# ×9
android ×1
debugging ×1
file ×1
file-exists ×1
game-engine ×1
gameobject ×1
if-statement ×1
inheritance ×1
unity5 ×1