本文整理汇总了C#中UnityEngine.GameObject.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# GameObject.GetComponent方法的具体用法?C# GameObject.GetComponent怎么用?C# GameObject.GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.GameObject
的用法示例。
在下文中一共展示了GameObject.GetComponent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnGUI
void OnGUI()
{
GUILayout.Box("Legacy Effect Scale Editor", GUILayout.Width(295));
EditorGUILayout.Space();
Effect = (GameObject)EditorGUILayout.ObjectField("Legacy Effect", Effect, typeof(GameObject), true);
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.Space();
Scale = float.Parse(EditorGUILayout.TextField("Scale Change Value", Scale.ToString()));
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.Space();
if (GUILayout.Button("Scale Apply", GUILayout.Height(70)))
{
if (Effect.GetComponent<csLegacyEffectChanger>() != null)
Effect.GetComponent<csLegacyEffectChanger>().LegacyEffectScaleChange(Scale);
else
{
Effect.AddComponent<csLegacyEffectChanger>();
Effect.GetComponent<csLegacyEffectChanger>().LegacyEffectScaleChange(Scale);
}
DestroyImmediate(Effect.GetComponent<csLegacyEffectChanger>());
}
}
示例2: OnMouseDown
public void OnMouseDown()
{
//pego a unidade selecionada atravez do controlador de jogo
GameObject selecionado = gameObject.transform.parent.parent.parent.GetComponent<ControladorDeJogo>().objetoSelecionado;
//Se tiver algum objeto selecionado, mando a unidade selecionada se mover para o objeto clicado
if(selecionado != null)
{//Se tiver alguma unidade selecionada
if(tropaJogador == null)
{//E se nao tiver nem uma unidade nesse alvo (unidade do jogador)
//Defino que tem uma unidade vindo pra ca
tropaJogador = selecionado;
//Se a unidade que esta vindo estiver vindo de um outro alvo, limpo o alvo antigo
if(tropaJogador.GetComponent<ComportamentoDeUnidade>().alvoAtual != null)
tropaJogador.GetComponent<ComportamentoDeUnidade>().alvoAtual.GetComponent<AcoesJogadorAlvo>().tropaJogador = null;
//Mando a unidade se mover para o alvo atual
tropaJogador.GetComponent<ComportamentoDeUnidade>().moverSoldados(gameObject);
//E digo que esse alvo e o novo destino dele
tropaJogador.GetComponent<ComportamentoDeUnidade>().alvoAtual = gameObject;
//atualizar as cores do alvo
atualizarCores();
}
else
gameObject.transform.parent.parent.parent.GetComponent<ControladorDeJogo>().hud.GetComponent<ControladorDeInterface>().escreverMensagem("Nao pode haver dois grupos em um mesmo alvo");
}
}
示例3: Move
private void Move(GameObject prefab)
{
//move object upwards over time * speed
Vector2 pos = prefab.GetComponent<RectTransform>().anchoredPosition;
pos.y += 1 * speed * Time.deltaTime;
prefab.GetComponent<RectTransform>().anchoredPosition = pos;
}
示例4: Start
void Start()
{
levelClock = GameObject.Find("gameBase").GetComponent<levelClock>();
spaceship = GameObject.Find("spaceship");
rb = spaceship.GetComponent<Rigidbody2D>();
body = spaceship.GetComponent<Transform>();
}
示例5: Fire
void Fire()
{
// 프리팹 동적 생성
target_projectile = (GameObject)Instantiate(projectile, new Vector3(firePos.x,firePos.y), fireAngle);
target_projectile.GetComponent<BazookaCtrl>().globalId = GetComponentInParent<NetPlayerCtrl>().globalId;
target_projectile.GetComponent<BazookaCtrl>().shotPower = fireForce;
}
示例6: Update
// Update is called once per frame
void Update()
{
timerText = GameObject.Find("dynamic timer text");
monster = GameObject.Find("Player");
timer += Time.deltaTime;
gameOver += Time.deltaTime;
if (timer > 1.0f)
{
transform.Rotate((float)180/levelTime, 0.0f, 0.0f);
timer = 0.0f;
}
if (levelTime - gameOver >= 0)
{
timerText.GetComponent<Timer>().timer = levelTime - gameOver;
}
if (gameOver > levelTime && GameObject.Find("Plant") != null)
{
//gameOverText.active = true;
nextLevelBut.transform.Translate(1,0,0);
gameOverText.GetComponent<GUIText>().text = "You Survived The Day Victory Is Yours!";
monster.GetComponent<AIFollow>().Stop();
if (monster.GetComponent<AIFollow>().speed <= 0)
{
Destroy(monster);
}
gameOver = 0.0f;
}
}
示例7: AddClusterScripts
void AddClusterScripts(GameObject iObject, bool iChildren)
{
//MiddleVRTools.Log("AddCluster to " + iObject);
//print("AddCluster to " + iObject);
{
if (iObject.GetComponent<VRShareTransform>() == null)
{
VRShareTransform script = iObject.AddComponent<VRShareTransform>() as VRShareTransform;
script.Start();
}
if (iObject.GetComponent<VRApplySharedTransform>() == null)
{
VRApplySharedTransform script = iObject.AddComponent<VRApplySharedTransform>() as VRApplySharedTransform;
script.Start();
}
}
if( iChildren == true )
{
foreach (Transform child in iObject.transform)
{
GameObject childObject = child.gameObject;
//print("Child : " + childObject);
AddClusterScripts(childObject, true);
}
}
}
示例8: Update
void Update()
{
if (ritualStart)
{
GetComponent<EllipsoidParticleEmitter>().emit = true;
GetComponent<ParticleAnimator>().damping = timeAndDumbing;
timeAndDumbing += 0.01f;
if (isTriggered & !isCreated)
{
GetComponent<EllipsoidParticleEmitter>().emit = true;
enemy = Instantiate(enemyPrefab, transform.position, Quaternion.identity) as GameObject;
monkGroup.GetComponent<InputHandler>().enemy = enemy;
enemy.GetComponent<Enemy>().canvasPlane = plane;
enemy.GetComponent<Enemy>().canvasText = text;
isCreated = true;
monkGroup.GetComponent<GroupMovement>().StopMovement();
}
if (timeAndDumbing >= 1)
{
GetComponent<EllipsoidParticleEmitter>().emit = false;
enemy.GetComponent<EnemyMovement>().StartMovement();
monkGroup.GetComponent<GroupMovement>().StartMovement();
monkGroup.GetComponent<GroupMovement>().movementSpeed = 5.0f;
Destroy(this.gameObject, 2.0f);
}
}
}
示例9: PlaySounds
public static void PlaySounds(GameObject obj, AudioClip[] clips)
{
if(clips == null || clips.Length == 0) return;
obj.GetComponent<AudioSource>().clip = clips[Random.Range(0, clips.Length)];
obj.GetComponent<AudioSource>().Play();
}
示例10: CreateDecal
public static GameObject CreateDecal(Material mat, Rect uvCoords, float scale)
{
GameObject decal = new GameObject();
decal.name = "Decal" + decal.GetInstanceID();
decal.AddComponent<MeshFilter>().sharedMesh = DecalMesh("DecalMesh" + decal.GetInstanceID(), mat, uvCoords, scale);
decal.AddComponent<MeshRenderer>().sharedMaterial = mat;
#if UNITY_5
decal.GetComponent<MeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
#else
decal.GetComponent<MeshRenderer>().castShadows = false;
#endif
qd_Decal decalComponent = decal.AddComponent<qd_Decal>();
decalComponent.SetScale(scale);
decalComponent.SetTexture( (Texture2D)mat.mainTexture );
decalComponent.SetUVRect(uvCoords);
#if DEBUG
decal.AddComponent<qd_DecalDebug>();
#endif
return decal;
}
示例11: PlayerDeath
IEnumerator PlayerDeath(GameObject temp)
{
//player.GetComponent<PlatformerAnimation>().PlayerDied();
temp = this.player;
if(temp.name=="Player"){
temp.GetComponent<PlayerController>().RemoveControl();
AudioSource.PlayClipAtPoint(deathSound, temp.transform.position);
yield return new WaitForSeconds(2.0f);
temp.GetComponent<PlayerPhysics>().Reset();
//player.GetComponent<PlatformerAnimation>().PlayerLives();
temp.GetComponent<PlayerController>().GiveControl();
}
else {
BoxController control = temp.GetComponent<BoxController>();
if(control.velCheck()){
AudioSource.PlayClipAtPoint(boxPop, temp.transform.position);
//yield return new WaitForSeconds(2.0f);
temp.GetComponent<PlayerPhysics>().Reset();
}
}
}
示例12: Start
// Use this for initialization
void Start()
{
rend = GetComponent<Renderer>();
pl = GameObject.FindGameObjectWithTag("Player");
Physics2D.IgnoreCollision(GetComponent<Collider2D>(), pl.GetComponent<Collider2D>());
Physics2D.IgnoreCollision(GetComponent<Collider2D>(), pl.GetComponent<CircleCollider2D>());
}
示例13: Create
public static Bone Create() {
GameObject b = new GameObject("Bone");
Undo.RegisterCreatedObjectUndo(b, "Add child bone");
b.AddComponent<Bone>();
if (Selection.activeGameObject != null) {
GameObject sel = Selection.activeGameObject;
b.transform.parent = sel.transform;
if (sel.GetComponent<Bone>() != null) {
Bone p = sel.GetComponent<Bone>();
b.transform.position = p.Head;
b.transform.localRotation = Quaternion.Euler(0, 0, 0);
}
}
Skeleton skel = b.transform.root.GetComponentInChildren<Skeleton>();
if (skel != null) {
Bone[] bones = skel.GetComponentsInChildren<Bone>();
int index = bones.Max(bn => bn.index) + 1;
b.GetComponent<Bone>().index = index;
skel.CalculateWeights();
}
Selection.activeGameObject = b;
return b.GetComponent<Bone>();
}
示例14: respawnCharacter
private static EffectStop respawnCharacter(GameObject character)
{
return () =>
{
var manager = GameObject.Find("GameManager").GetComponent<GameManager>();
var combatData = character.GetComponent<Combat>();
var characterData = character.GetComponent<Character>();
// Consider character to be alive
combatData.dead = false;
combatData.selectable = true;
// Restore health
combatData.health = combatData.maxHealth;
combatData.mana = combatData.maxMana();
// Move Character to correct position
var spawn = character.tag == "TeamA" ?
manager.bluespawn[UnityEngine.Random.Range(0, manager.bluespawn.Length)] :
manager.redspawn[UnityEngine.Random.Range(0, manager.redspawn.Length)];
character.transform.position = spawn.transform.position;
// Set animation state to alive
characterData.setAnimation_State(characterData.dead_State, false);
// Enable movement
character.GetComponent<NavMeshAgent>().enabled = true;
character.GetComponent<Rigidbody>().useGravity = true;
};
}
示例15: SetAttacker
public void SetAttacker(GameObject g)
{
attacker = g;
if (attacker.gameObject.tag == "Player")
{
direction = attacker.GetComponent<CharacterMovementScript>().Direction;
aimMode = attacker.GetComponent<CharacterMovementScript>().AimMode;
if (aimMode)
{
testIKScript = GameObject.FindGameObjectWithTag("Player").GetComponent<TestIKScript>();
position = testIKScript.lookObj.position;
this.transform.LookAt(position);
}
else
{
//Debug.Log("Tossed Grenade");
position = GameObject.FindGameObjectWithTag("LookAtObj").transform.position;
this.transform.LookAt(position);
}
}
else if (attacker.GetComponent<GuardController>())
{
if (attacker.GetComponent<GuardController>().movingSpeed < 0)
direction = true;
else
direction = false;
}
else
{
position = GameObject.FindGameObjectWithTag("Player").transform.position;
this.transform.LookAt(position);
}
}