本文整理汇总了C#中GameObject.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# GameObject.GetComponent方法的具体用法?C# GameObject.GetComponent怎么用?C# GameObject.GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GameObject
的用法示例。
在下文中一共展示了GameObject.GetComponent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public static void Create(Vector3 pos, string text, ColorRgba color)
{
GameObject pe = new GameObject(GameRes.Data.Prefabs.PowerupEffect_Prefab);
pe.GetComponent<PowerupEffect>().Text = text;
pe.GetComponent<TextRenderer>().ColorTint = color;
pe.Transform.Pos = pos;
Scene.Current.RegisterObj(pe);
}
示例2: DropDownListButton
public DropDownListButton(GameObject btnObj)
{
gameobject = btnObj;
rectTransform = btnObj.GetComponent<RectTransform>();
btnImg = btnObj.GetComponent<Image>();
btn = btnObj.GetComponent<Button>();
txt = rectTransform.FindChild("Text").GetComponent<Text>();
img = rectTransform.FindChild("Image").GetComponent<Image>();
}
示例3: OnJoinMatch
public void OnJoinMatch(GameObject script)
{
string server_Name = script.GetComponent<MainMenuButtons_script> ().roomNameJoin;
string server_Password = script.GetComponent<MainMenuButtons_script> ().roomPasswordJoin;
foreach (var match in manager.matches) {
if (match.name == server_Name) {
manager.matchMaker.JoinMatch (match.networkId, server_Password, manager.OnMatchJoined);
}
}
}
示例4: FindCollisionPoint
private static CollisionPoint FindCollisionPoint(GameObject gameObject, GameObject other, Vector2 oldPosition, Vector2 newPosition)
{
if (gameObject.GetComponent<Collider>() is CircleCollider){
if (other.GetComponent<Collider>() is CircleCollider)
{
CircleCollider objCollider = (CircleCollider) gameObject.GetComponent<Collider>();
CircleCollider otherCollider = (CircleCollider) other.GetComponent<Collider>();
float distance = Vector2.Distance(newPosition, other.Position);
if (distance < objCollider.Radius + otherCollider.Radius)
{
return new CollisionPoint(oldPosition);
}
}
else if (other.GetComponent<Collider>() is SquareCollider)
{
CircleCollider objCollider = (CircleCollider)gameObject.GetComponent<Collider>();
SquareCollider otherCollider = (SquareCollider)other.GetComponent<Collider>();
float distanceX = other.Position.X - newPosition.X;
float distanceY = other.Position.Y - newPosition.Y;
bool xCollision = Math.Abs(distanceX) < otherCollider.Width/2 + objCollider.Radius;
bool yCollision = Math.Abs(distanceY) < otherCollider.Height / 2 + objCollider.Radius;
if (xCollision && yCollision)
{
float xMove = newPosition.X - oldPosition.X;
float yMove = newPosition.Y - oldPosition.Y;
if (oldPosition.X + objCollider.Radius < other.Position.X - otherCollider.Width/2 ||
oldPosition.X - objCollider.Radius > other.Position.X + otherCollider.Width / 2)
{
oldPosition.Y += yMove;
//newPosition = new Vector2(0f, oldPosition.Y + yMove);
}
if (oldPosition.Y + objCollider.Radius < other.Position.Y - otherCollider.Height / 2 ||
oldPosition.Y - objCollider.Radius > other.Position.Y + otherCollider.Height / 2)
{
oldPosition.X += xMove;
//newPosition.X += oldPosition.X + xMove;
//newPosition = new Vector2(oldPosition.X + xMove, 0f);
}
return new CollisionPoint(oldPosition);
}
}
}
return null;
}
示例5: CloneGameObject
[Test] public void CloneGameObject()
{
Random rnd = new Random();
GameObject source = new GameObject("ObjectA");
source.AddComponent(new TestComponent(rnd));
GameObject target = source.DeepClone();
Assert.AreNotSame(source, target);
Assert.AreEqual(source.Name, target.Name);
Assert.AreEqual(source.GetComponent<TestComponent>(), target.GetComponent<TestComponent>());
Assert.AreNotSame(source.GetComponent<TestComponent>(), target.GetComponent<TestComponent>());
Assert.AreNotSame(source.GetComponent<TestComponent>().TestReferenceList, target.GetComponent<TestComponent>().TestReferenceList);
}
示例6: CheckCollision
internal static Vector2 CheckCollision(GameObject gameObject, Vector2 position)
{
foreach (GameObject other in GameObject.GameObjects)
{
if (other == gameObject){
continue;
}
Projectile projectile = gameObject.GetComponent<Projectile>();
Projectile projectileOther = other.GetComponent<Projectile>();
if ((projectile != null && projectile.Owner == other) || (projectileOther != null && projectileOther.Owner == gameObject))
{
continue;
}
Collider otherCollider = other.GetComponent<Collider>();
if (otherCollider == null)
{
continue;
}
// if inside
CollisionPoint collisionPoint = FindCollisionPoint(gameObject, other, gameObject.Position, position);
if (collisionPoint != null)
{
position = collisionPoint.Point;
gameObject.OnCollision(other, position);
}
}
return position;
}
示例7: OnStart
public void OnStart()
{
GameObject panel = GameObject.GetGameObjectByName("PuzzleButton1").transform.GetChild(0).gameObject;
panel1 = GetScript<BoobyTrapDeactivator>(panel);
panel = GameObject.GetGameObjectByName("PuzzleButton2").transform.GetChild(0).gameObject;
panel2 = GetScript<BoobyTrapDeactivator>(panel);
panel = GameObject.GetGameObjectByName("PuzzleButton3").transform.GetChild(0).gameObject;
panel3 = GetScript<BoobyTrapDeactivator>(panel);
panel = GameObject.GetGameObjectByName("PuzzleButton4").transform.GetChild(0).gameObject;
panel4 = GetScript<BoobyTrapDeactivator>(panel);
trapLightW = GameObject.GetGameObjectByName("TrapLightW");
trapLightR1 = GameObject.GetGameObjectByName("TrapLightR1");
trapLightR1script = GetScript<PulsingLightScript>(trapLightR1);
trapLightR2 = GameObject.GetGameObjectByName("TrapLightR2");
trapLightR2script = GetScript<PulsingLightScript>(trapLightR2);
trapLightR3 = GameObject.GetGameObjectByName("TrapLightR3");
trapLightR3script = GetScript<PulsingLightScript>(trapLightR3);
trapLightR4 = GameObject.GetGameObjectByName("TrapLightR4");
trapLightR4script = GetScript<PulsingLightScript>(trapLightR4);
poisonGas = GameObject.GetGameObjectByName("TSR_PoisonGas");
gas = poisonGas.GetComponent<CParticleEmitter>();
gasScript = GetScript<TransformRiserScript>(poisonGas);
GameObject boobyControllerObj = GameObject.GetGameObjectByName("TSR_TrapController");//trapControllerName);
controllerScript = GetScript<BoobyTrapDeactivatorController>(boobyControllerObj);
gasTimerShutdown = gas.mEmitterProperty.mMaxLifetime;
mSound = gameObject.RequireComponent<CSound>();
}
示例8: Create
public static void Create(Vector3 pos, float intensity)
{
GameObject explo = new GameObject(GameRes.Data.Prefabs.ExploEffect_Prefab);
explo.GetComponent<ExploEffect>().Intensity = intensity;
explo.Transform.Pos = pos;
Scene.Current.RegisterObj(explo);
}
示例9: UpdatePosition
private void UpdatePosition(GameObject obj, float speed)
{
Vector3 pos = obj.Transform.Pos;
float textureWidth = obj.GetComponent<SpriteRenderer>().SharedMaterial.Res.MainTexture.Res.Size.X;
pos.X -= speed;
if (pos.X < -textureWidth) pos.X += textureWidth;
obj.Transform.Pos = pos;
}
示例10: TestGameObject
public new bool TestGameObject(GameObject go)
{
var result = false;
var c = go.GetComponent(Type, true);
if (c != null)
{
result = base.TestGameObject(go);
}
return result;
}
示例11: OnCollision
public override void OnCollision(GameObject other, Vector2 position)
{
var health = other.GetComponent<Health>();
AttachedTo.MarkForDestruction();
if (health == null)
return;
health.CurrentHealth -= Damage;
Console.WriteLine(health.CurrentHealth);
//other.MarkForDestruction();
}
示例12: BehaviourTreeNode
public BehaviourTreeNode(
Game1 game,
GameObject parent,
BehaviourNodeType type)
{
this._type = type;
this._state = BehaviourNodeState.Ready;
this._children = new List<BehaviourTreeNode>();
this._behaviourComponent = (BehaviourComponent)parent.GetComponent(ComponentType.Behaviour);
this._parent = parent;
this._game = game;
}
示例13: OnTriggerEnter
void OnTriggerEnter(GameObject collider)
{
var bc = collider.GetComponent<BulletControl>();
if (bc != null)
{
if (bc.Side == Side.Player)
{
Destroy(Owner);
Destroy(collider);
}
}
}
示例14: Matches
/// <summary>
/// Returns true if the specified <see cref="GameObject"/> has any of the matching
/// <see cref="Component"/> types, or if the filter is empty.
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public bool Matches(GameObject obj)
{
if (this.typeIds.Count == 0) return true;
this.UpdateTypeCache();
foreach (Type type in this.typeCache)
{
if (obj.GetComponent(type) != null)
return true;
}
return false;
}
示例15: GetBestPath
public bool GetBestPath(GameObject obj, GameTime gameTime, AStarGraph graph)
{
Stack<AStarNode> path = new Stack<AStarNode>();
Transform2DComponent transformComponent =
(Transform2DComponent)obj.GetComponent(ComponentType.Transform2D);
AStarComponent aStarComponent =
(AStarComponent)obj.GetComponent(ComponentType.AStar);
if (transformComponent == null || aStarComponent == null)
{
return false;
}
AStarNode entityNode = graph.GetClosestNode(transformComponent.GetTranslation());
aStarComponent.CurrentNode = entityNode;
AStarNode goalNode;
if (aStarComponent.Follow)
{
GameObject entity = aStarComponent.EntityToFollow;
Transform2DComponent entityTransformComponent =
(Transform2DComponent)entity.GetComponent(ComponentType.Transform2D);
aStarComponent.EntityToFollowPosBuffer = entityTransformComponent.GetTranslation();
goalNode = graph.GetClosestNode(aStarComponent.EntityToFollowPosBuffer);
}
else
{
goalNode = graph.GetClosestNode(aStarComponent.GoalPosition);
}
this.resolvePath(aStarComponent, entityNode, goalNode, graph);
return true;
}