本文整理汇总了C#中Target.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# Target.GetComponent方法的具体用法?C# Target.GetComponent怎么用?C# Target.GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Target
的用法示例。
在下文中一共展示了Target.GetComponent方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnCollisionEnter
public void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "target")
{
string targetname = collision.gameObject.name;
GameObject targetobject = GameObject.Find(targetname);
target = targetobject.GetComponent<Target>();
//Debug.Log(target.GetComponent<Renderer>().material.color == Color.red);
if (target.GetComponent<Renderer>().material.color == Color.red)
{
if (colcount >= target.collisionsRequired)
{
target.GetComponent<Renderer>().material.color = Color.green;
target.Invoke("openDoor", 1);
score = 500 + 500* colcount;
GameObject scoretextobject = GameObject.Find("Score");
Text scoretext = scoretextobject.GetComponentInChildren<Text>();
float currentScore = Single.Parse(scoretext.text);
score += currentScore;
scoretext.text = score.ToString();
}
else
{
target.playSound("miss");
target.GetComponent<Renderer>().material.color = Color.yellow;
Invoke("changeRed", 2);
}
}
}
else
{
GetComponent<AudioSource>().Play();
colcount++;
}
}
示例2: PerformAttack
protected virtual void PerformAttack(Target src, Target target)
{
if (target == null)
return;
mReloadTimer = Random.Range (ReloadTime * (1f - ReloadVariance), ReloadTime * (1f + ReloadVariance));
Unit e = (Unit) target.GetComponent(typeof(Unit));
e.Damage(this.Damage);
}
示例3: PerformAttack
protected override void PerformAttack(Target src, Target target)
{
if (target == null)
return;
mReloadTimer = Random.Range (ReloadTime * (1f - ReloadVariance), ReloadTime * (1f + ReloadVariance));
Unit e = (Unit) target.GetComponent(typeof(Unit));
e.Damage(this.Damage);
GameObject o = (GameObject) GameObject.Instantiate(mProjectilePrefab);
Arrow a = (Arrow) o.GetComponent(typeof(Arrow));
a.transform.position = src.transform.position;
a.SetDestination(target.transform.position);
}
示例4: AttackTarget
private void AttackTarget(Target target)
{
if (target == null || HasLowerPriority(target))
return;
if (target == null)
Debug.Break ();
mTargetPriority = TargetPriority(target);
if (target is Unit) {
Unit u = (Unit)target.GetComponent (typeof(Unit));
mTargetSquad = u.Squad;
AttackEnemySquad (u.Squad);
} else if (target is Tower) {
mTargetSquad = null;
Tower t = (Tower)target.GetComponent (typeof(Tower));
AttackEnemyTower (t);
}
}
示例5: AttackTarget
private void AttackTarget(Unit who, Target enemyUnit)
{
if (who == null || enemyUnit == null)
Debug.Break();
IsEngaged = true;
Unit u = (Unit) enemyUnit.GetComponent(typeof(Unit));
mTargetSquad = u.Squad;
AttackEnemySquad(who, u);
}