本文整理汇总了C#中UnityEngine.Transform.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# Transform.GetComponent方法的具体用法?C# Transform.GetComponent怎么用?C# Transform.GetComponent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Transform
的用法示例。
在下文中一共展示了Transform.GetComponent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetColor
void SetColor(Transform _transform, Color _color)
{
mText = _transform.GetComponent<Text> ();
if (mText != null){
mText.color = _color;
}
mLight = _transform.light;
if (mLight != null){
mLight.color = _color;
}
mImage = _transform.GetComponent<Image> ();
if (mImage != null) {
mImage.color = _color;
}
mSpriteRender = _transform.GetComponent<SpriteRenderer> ();
if (mSpriteRender != null) {
mSpriteRender.color = _color;
}
if (_transform.renderer != null) {
mMat = _transform.renderer.material;
if (mMat != null) {
mMat.color = _color;
}
}
if (includeChilds) {
for (int i = 0; i < _transform.childCount; ++i) {
Transform child = _transform.GetChild(i);
SetColor(child, _color);
}
}
}
示例2: Update
private void Update()
{
if (GetComponent<ActionsOnlyInCanvas>() == null ||
GetComponent<ActionsOnlyInCanvas>().IsMousePosInsideCanvas)
{
var ray = PlayerCamera.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 100))
{
CurrentHex = hit.transform;
if (Input.GetMouseButton(0))
if (HexSelected != null) HexSelected(this, new HexCoordEventArgs(CurrentHex.GetComponent<HexData>().HexPosition));
if (HexHitted != null) HexHitted(this, new HexCoordEventArgs(CurrentHex.GetComponent<HexData>().HexPosition));
}
else if (CurrentHex)
{
CurrentHex = null;
if (NoHexHitted != null) NoHexHitted(this, EventArgs.Empty);
}
else if (Input.GetMouseButton(0))
{
if (NoHexSelected != null) NoHexSelected(this, EventArgs.Empty);
}
}
}
示例3: colorFrom
public Tween colorFrom( Transform trans, float duration, Color targetColor, string materialProperty = "_Color", bool isRelativeTween = false )
{
var currentColor = trans.GetComponent<Renderer>().material.GetColor( materialProperty );
trans.GetComponent<Renderer>().material.SetColor( materialProperty, targetColor );
return colorTo( trans, duration, currentColor, materialProperty, isRelativeTween );
}
示例4: Start
void Start ()
{
player = GameObject.FindWithTag ("Player").transform;
pHealth = player.GetComponent<PlayerHealth> ();
pAttack = player.GetComponent<PlayerAttack> ();
eHealth = GetComponent<EnemyHealth> ();
Rigidbody = GetComponent<Rigidbody> ();
}
示例5: Awake
void Awake ()
{
PTank = GameObject.Find("PlayerTank(Clone)").transform;
ETank = GameObject.Find("EnemyTank_Hard(Clone)").transform;
pHealth = PTank.GetComponent<PlayerHealth> ();
eHealth = ETank.GetComponent<EnemyHealth> ();
eMove = ETank.GetComponent<EnemyMovement> ();
}
示例6: Activate
public override void Activate(BTDatabase database)
{
base.Activate(database);
_trans = database.transform;
seeker = _trans.GetComponent<Seeker>();
controller = _trans.GetComponent<CharacterController>();
seeker.pathCallback += OnPathComplete;
}
示例7: BuffCalculation
public BuffCalculation(Transform character)
{
Character = character;
property = character.GetComponent<CharacterProperty>();
buffList = character.GetComponent<BuffList>();
selection = character.GetComponent<CharacterSelect>();
addBuff = (BuffType[])buffList.addBuff.Clone();
deBuff = (BuffType[])buffList.deBuff.Clone();
playerSide = property.Player;
}
示例8: Fire
/// <summary>
/// Fire a specified projectile.
/// </summary>
/// <param name="projectile">Projectile.</param>
/// <param name="lookAt">Look at direction.</param>
protected void Fire(Transform projectile, Vector3 lookAt)
{
projectile.position = this.transform.TransformPoint(this.spawnPosition);
var component = projectile.GetComponent<Projectile>();
component.targetTag = this.targetTag;
component.targetPosition = lookAt;
var particles = projectile.GetComponent<ParticleSystem>();
particles.Clear(true);
particles.Play(true);
}
示例9: FindAnimatorRecursive
// Finds the first Animator/Animation up the hierarchy
private void FindAnimatorRecursive(Transform t, bool findInChildren) {
if (isAnimated) return;
animator = t.GetComponent<Animator>();
animation = t.GetComponent<Animation>();
if (isAnimated) return;
if (animator == null && findInChildren) animator = t.GetComponentInChildren<Animator>();
if (animation == null && findInChildren) animation = t.GetComponentInChildren<Animation>();
if (!isAnimated && t.parent != null) FindAnimatorRecursive(t.parent, false);
}
示例10: PlayAnimation
public static bool PlayAnimation (Transform sprite, string clipName, bool changeWrapMode, WrapMode wrapMode, int frame)
{
#if tk2DIsPresent
tk2dSpriteAnimationClip.WrapMode wrapMode2D = tk2dSpriteAnimationClip.WrapMode.Once;
if (wrapMode == WrapMode.Loop)
{
wrapMode2D = tk2dSpriteAnimationClip.WrapMode.Loop;
}
else if (wrapMode == WrapMode.PingPong)
{
wrapMode2D = tk2dSpriteAnimationClip.WrapMode.PingPong;
}
if (sprite && sprite.GetComponent <tk2dSpriteAnimator>())
{
tk2dSpriteAnimator anim = sprite.GetComponent <tk2dSpriteAnimator>();
tk2dSpriteAnimationClip clip = anim.GetClipByName (clipName);
if (clip != null)
{
if (!anim.IsPlaying (clip))
{
if (changeWrapMode)
{
clip.wrapMode = wrapMode2D;
}
anim.Play (clip);
if (frame >= 0)
{
anim.ClipFps = 1f;
anim.SetFrame (frame);
}
}
return true;
}
return false;
}
#else
Debug.Log ("The 'tk2DIsPresent' preprocessor is not defined - check your Build Settings.");
#endif
return true;
}
示例11: Act
public override void Act(Transform player, Transform npc)
{
//攻撃フラグを初期化
npc.GetComponent<EnemyCtrl> ().StateStartCommon ();
//ターゲット地点をプレーヤーポジションに設定
this.SetDest (player);
//ターゲット地点に回転
if(IsTestScene())
this.SetRot (npc, npc.position);
//目的地をプレイヤーに変更
npc.GetComponent<CharaMove> ().SendMessage ("SetDestination", destPos);
}
示例12: SetupGeometryAndAppearance
public override void SetupGeometryAndAppearance()
{
Tip = part.FindModelTransform("Tip");
Root = part.FindModelTransform("Root");
SMRcontainer = part.FindModelTransform("Collider");
wingSMR = SMRcontainer.GetComponent<SkinnedMeshRenderer>();
}
示例13: Reason
public override void Reason(Transform player, Transform npc)
{
this.SetDest (player);
this.SetDist (Vector3.Distance (npc.position, destPos));
if(this.LessThanCheckReach(dist, 2.0f))
{
Debug.Log("Switch to Attack state");
npc.GetComponent<EnemyCtrl>().SetTransition(Transition.ReachPlayer);
}
else if(this.GreaterThanCheckReach(dist, 10.0f))
{
Debug.Log("Switch to Search state");
npc.GetComponent<EnemyCtrl>().SetTransition(Transition.LostPlayer);
}
}
示例14: Create
public static PathFollower Create(Transform transform)
{
var pathFollower = transform.GetComponent<PathFollower>();
if (pathFollower == null) pathFollower = transform.gameObject.AddComponent<PathFollower>();
pathFollower._transform = transform;
return pathFollower;
}
示例15: RemoveRagdollComponents
/// <summary>
/// Removes all the ragdoll components (except Cloth colliders), including compound colliders that are not used by Cloth. Components on the 'target' GameObject will not be touched for they are probably not ragdoll components, but required by a character controller.
/// </summary>
/// <param name="target">Target.</param>
public static void RemoveRagdollComponents(Transform target, int characterControllerLayer)
{
if (target == null) return;
// Get rid of all the ragdoll components on the target
Rigidbody[] rigidbodies = target.GetComponentsInChildren<Rigidbody>();
Cloth[] cloths = target.GetComponentsInChildren<Cloth>();
for (int i = 0; i < rigidbodies.Length; i++) {
if (rigidbodies[i].gameObject != target.gameObject) {
var joint = rigidbodies[i].GetComponent<Joint>();
var collider = rigidbodies[i].GetComponent<Collider>();
if (joint != null) DestroyImmediate(joint);
if (collider != null) {
if (!IsClothCollider(collider, cloths)) DestroyImmediate(collider);
else collider.gameObject.layer = characterControllerLayer;
}
DestroyImmediate(rigidbodies[i]);
}
}
// Get rid of (compound) colliders that are not used by Cloth
Collider[] colliders = target.GetComponentsInChildren<Collider>();
for (int i = 0; i < colliders.Length; i++) {
if (colliders[i].transform != target && !IsClothCollider(colliders[i], cloths)) {
DestroyImmediate(colliders[i]);
}
}
// Get rid of the PuppetMaster
var puppetMaster = target.GetComponent<PuppetMaster>();
if (puppetMaster != null) DestroyImmediate(puppetMaster);
}