我正在尝试在 Unity 中实现塔防游戏,但我不知道如何将速度或力分配给新的实例化对象(在创建者对象的脚本中)我有一个应该射击的塔一颗子弹射向敌人,触发了它的对撞机。这是塔的脚本:
function OnTriggerEnter(other:Collider){
if(other.name=="Enemy")
{
ShootBulletTo(other.transform);
}
}
function ShootBulletTo(target:Transform)
{//public var Bullet:Transform
var BulletClone = Instantiate(Bullet,transform.position, Quaternion.identity); // ok
BulletClone.AddForce(target.position); //does not compile since Transform.AddForce() does not exist.
}
我想问题是我必须使用一个Transform
变量来实例化,但我需要一个GameObject
速度、力等变量。那么我怎样才能用初始速度实例化子弹呢?感谢帮助。