unityscript中的对象敌人
我可以在unitycript中作为一个具有“健康”、“速度”和“耐力”的对象“敌人”。并删除该对象,还是一次删除多个对象?
class enemy {
health = 100
speed = 10
stamina = 200
}
for 0 to 10
{
enemyBig = new Enemy ()
}
if keydown (space)
{
delete all.enemyBig
}
unityscript中的这段代码如何正确?
I can do in unitycript as an object "enemy" that has "health", "speed" and "stamina". And to delete the object, or several at once?
class enemy {
health = 100
speed = 10
stamina = 200
}
for 0 to 10
{
enemyBig = new Enemy ()
}
if keydown (space)
{
delete all.enemyBig
}
How would this code in unityscript correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 javascript 中,要定义类,您需要创建一个函数。
然后将方法放在原型上(因为javascript使用原型继承。)
当您执行上述操作来定义方法时,该方法就是实例方法;即每个对象都有自己的方法副本。如果你想定义一个“静态”方法,你只需将该方法放在类上,
区别在于前者你可以做
,而后者你可以做
In javascript, to define a class you create a function.
and then to put methods on the prototype (because javascript uses prototypal inheritance.)
when you do the above to define a method, the method is an instance method; i.e. every object has its own copy of the method. If you want to define a 'static' method, you just put the method on the class
the difference is for the former you can do
and for the latter you do
要同时追踪所有敌人,您需要一个数组。那里有一个很好的教程:
To keep track of all your enemies at once, what you need is called an array. There's a good tutorial there:
实现对象:
就删除对象而言,如果没有其他引用,垃圾收集器将处理该对象。
但是,从问题来看,仅仅知道这些信息并不能让你走得更远。 拿一本关于 JavaScript 的书和/或做一些在线研究以真正了解 JavaScript 的基础知识。
To implement an object:
As far as deleting an object, the garbage collector will take care of the object if it has no other references to it.
But, from the question, it looks like just knowing this information won't carry you far. Grab a book on JavaScript and/or do some online research to really understand the fundamentals of JavaScript.