本文整理汇总了C#中GameObject.HasComponent方法的典型用法代码示例。如果您正苦于以下问题:C# GameObject.HasComponent方法的具体用法?C# GameObject.HasComponent怎么用?C# GameObject.HasComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GameObject
的用法示例。
在下文中一共展示了GameObject.HasComponent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Destroy
public static void Destroy(GameObject obj)
{
if (ObjectPool.Contains(obj))
ObjectPool.Add(obj);
else
{
if (obj.HasComponent<NetworkIdentity>())
NetworkServer.Destroy(obj);
else
Object.Destroy(obj);
}
}
示例2: MustCheckCollision
protected bool MustCheckCollision(GameObject obj1, GameObject obj2)
{
if (this._collisionTypeToCheck == CollisionType.All)
{
return true;
}
else if (this._collisionTypeToCheck == CollisionType.Action)
{
if (obj1.HasComponent(ComponentType.IsAction) && obj2.HasComponent(ComponentType.IsCharacter))
{
return true;
}
}
else if (this._collisionTypeToCheck == CollisionType.Physical)
{
if (obj1.HasComponent(ComponentType.IsPhysical) && obj2.HasComponent(ComponentType.IsPhysical))
{
return true;
}
}
return false;
}
示例3: Update
public void Update(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
{
if (CommandMap[up].Evaluate())
{
Owner.QueryComponent<Identity2D>().Transform.Position += new Vector2(0, -Speed);
if (Owner.HasComponent<SpriteAnimator>() && Animate && UpAnimation != null)
Owner.QueryComponent<SpriteAnimator>().CurrentAnimation = UpAnimation;
}
if (CommandMap[down].Evaluate())
{
Owner.QueryComponent<Identity2D>().Transform.Position += new Vector2(0, Speed);
if (Owner.HasComponent<SpriteAnimator>() && Animate && DownAnimation != null)
Owner.QueryComponent<SpriteAnimator>().CurrentAnimation = DownAnimation;
}
if (CommandMap[left].Evaluate())
{
Owner.QueryComponent<Identity2D>().Transform.Position += new Vector2(-Speed, 0);
if (Owner.HasComponent<SpriteAnimator>() && Animate && LeftAnimation != null)
Owner.QueryComponent<SpriteAnimator>().CurrentAnimation = LeftAnimation;
}
if (CommandMap[right].Evaluate())
{
Owner.QueryComponent<Identity2D>().Transform.Position += new Vector2(Speed, 0);
if (Owner.HasComponent<SpriteAnimator>() && Animate && RightAnimation != null)
Owner.QueryComponent<SpriteAnimator>().CurrentAnimation = RightAnimation;
}
var pos = Owner.QueryComponent<Identity2D>().Transform.Position;
if(oldPosition == pos)
if (Owner.HasComponent<SpriteAnimator>() && Animate)
Owner.QueryComponent<SpriteAnimator>().CurrentAnimation = null;
if (Owner.HasComponent<SpriteOscillator>() && Bobbing)
Owner.QueryComponent<SpriteOscillator>().Oscillate = oldPosition != pos;
oldPosition = pos;
}