当前位置: 首页>>代码示例>>C#>>正文


C# Target.GetComponent方法代码示例

本文整理汇总了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++;

        }


    }
开发者ID:ryanmak93,项目名称:Targets,代码行数:45,代码来源:Hit.cs

示例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);
    }
开发者ID:Chickenbottom,项目名称:CSS385_PowerOverwhelming,代码行数:10,代码来源:Weapon.cs

示例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);
    }
开发者ID:Chickenbottom,项目名称:CSS385_PowerOverwhelming,代码行数:16,代码来源:Pitchfork.cs

示例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);
        }
    }
开发者ID:Chickenbottom,项目名称:CSS385_PowerOverwhelming,代码行数:20,代码来源:Squad.cs

示例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);
    }
开发者ID:Chickenbottom,项目名称:CSS385_PowerOverwhelming,代码行数:10,代码来源:Squad.cs


注:本文中的Target.GetComponent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。