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


C# Rigidbody.GetComponent方法代码示例

本文整理汇总了C#中UnityEngine.Rigidbody.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# Rigidbody.GetComponent方法的具体用法?C# Rigidbody.GetComponent怎么用?C# Rigidbody.GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.Rigidbody的用法示例。


在下文中一共展示了Rigidbody.GetComponent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ApplyEffect

    protected override void ApplyEffect()
    {
        body = transform.parent.GetComponent<Rigidbody>();
        var v = body.velocity;

        var startNode = Grid.Instance.NodeFromWorldPoint(body.transform.position);
        int deltaX = 0;
        int deltaY = 0;
        if (Mathf.Abs(v.x) > Mathf.Abs(v.z))
            deltaX = v.x > 0 ? 1 : -1;
        else
            deltaY = v.z > 0 ? 1 : -1;

        int endX = startNode.gridX, endY = startNode.gridY;
        while (endX > 0 && endX < (Grid.Instance.gridSizeX - 1) && endY > 0 && endY < (Grid.Instance.gridSizeX - 1) && Grid.Instance.grid[endX, endY].walkable)
        {
            endX += deltaX;
            endY += deltaY;
        }
        endX -= deltaX;
        endY -= deltaY;
        endPos = Grid.Instance.grid[endX, endY].worldPosition;
        Debug.Log(startNode.worldPosition + " / " + v + "/" + endPos);

        body.GetComponent<Collider>().enabled = false;
        body.GetComponent<GridMovement>().Stop();
        body.GetComponent<GridMovement>().Freeze();
    }
开发者ID:ztranger,项目名称:Dove,代码行数:28,代码来源:BananaEffect.cs

示例2: OnTriggerEnter

 void OnTriggerEnter(Collider other)
 {
     if (other.GetComponent<Rigidbody> () != null) {
         player = other.gameObject.GetComponent<Rigidbody> ();
         bounceback = -player.velocity.y;
         Debug.Log (bounceback);
         player.velocity = new Vector3 (player.velocity.x, 0, 0);
         this.transform.localScale = compressedScale;
         framesTaken = 0;
         // Make it so hitting the trampoline can't kill the player
         if (player.name == "Character") {
             player.GetComponent<CharacterNavigate> ().previousVelocity = player.GetComponent<Rigidbody> ().velocity;
         }
     }
 }
开发者ID:mknooihuisen,项目名称:Ludum-Documentary,代码行数:15,代码来源:TrampolinePhysics.cs

示例3: shootAt

 void shootAt(GameObject obj)
 {
     bullet = Instantiate (bulletPrefab, transform.position + Vector3.up, Quaternion.identity) as Rigidbody;
     BulletScript bulletScript = (BulletScript)bullet.GetComponent (typeof(BulletScript));
     bulletScript.damage = 10;
     bullet.AddForce (BallisticVel (obj.transform), ForceMode.Impulse);
 }
开发者ID:rdemaeye,项目名称:mergePractice,代码行数:7,代码来源:TurretController.cs

示例4: Grab

    void Grab(Rigidbody rb)
    {
        rb.isKinematic = false;
        isGrapped = true;
        rb.MovePosition(hand.transform.position);
        rb.velocity = Vector3.zero;
        hj.connectedBody = rb;

        rb.GetComponent<Item>().checkIfKaverit();
    }
开发者ID:kersseliM,项目名称:syysjamit2015,代码行数:10,代码来源:Grapper.cs

示例5: AttachToObject

    public void AttachToObject(Rigidbody rBody)
    {
        if(rBody == null)
        {
            isFixedToWorld = true;
            return;
        }

        RigidJoint joint = rBody.GetComponent<RigidJoint>() ?? rBody.gameObject.AddComponent<RigidJoint>();

        if (IsConnectedToJoint(joint.GetComponent<Rigidbody>())) return;

        attachedJoints.Add(joint);
    }
开发者ID:VRWizards,项目名称:VR-Project,代码行数:14,代码来源:RigidJoint.cs

示例6: ApplyForceToTarget

        void ApplyForceToTarget(Vector3 contactPoint, Rigidbody rb)
        {

            if ( rb.GetComponent<NavMeshAgent>() != null)
                rb.GetComponent<NavMeshAgent>().enabled = false;

            rb.isKinematic = false;

            if ( rb.CompareTag("Enemy") )
            {
                //rb.GetComponent<Rigidbody>().isKinematic = false;
                explosionPower = explosionPower * 10;
            }
              
            rb.AddExplosionForce(explosionPower, contactPoint, blastRadius, .5f, ForceMode.Impulse);
            //Vector3 direction = rb.transform.position - transform.position;
            //rb.AddForceAtPosition(direction.normalized, contactPoint, ForceMode.Impulse);

            if ( rb.CompareTag("Enemy") )
            {
                Destroy(rb.gameObject, destroyTime);
            }
        }
开发者ID:jeffreyyankey,项目名称:TheEnchantedForest_prototype,代码行数:23,代码来源:ShotgunDamage.cs

示例7: UnflipBody

    private IEnumerator UnflipBody(Rigidbody body, Action callback)
    {
        float startTime = Time.time;

        while(BodyUneven(body))
        {
            body.GetComponent<PlayerHealth>().enabled = false;

            body.AddForce(Vector3.up * (4.0f - body.position.y) * 0.1f, ForceMode.VelocityChange);

            body.transform.rotation = Quaternion.Lerp(
                body.transform.rotation,
                Quaternion.identity,
                (Time.time - startTime) * 0.005f
                );

            yield return new WaitForFixedUpdate();
        }

        // Finished, call the callback
        callback();
        body.GetComponent<PlayerHealth>().enabled = true;
        body.isKinematic = false;
    }
开发者ID:ddoodm,项目名称:Mowdown,代码行数:24,代码来源:flipCounterController.cs

示例8: PongBall

    public PongBall(Rigidbody UnityBall,  Hashtable BallInfo)
    {
        this.actualBall = UnityBall;
        ballid = (string)BallInfo[FIELD_BALLID];
        this.actualBall.name = ballid;

        Hashtable vect = (Hashtable)BallInfo[FIELD_POSITION];
        position = PongSerializer.toVector(vect);
        actualBall.transform.position = position;

        vect = (Hashtable)BallInfo[FIELD_VELOCITY];
        velocity = PongSerializer.toVector(vect);
        actualBall.GetComponent<Rigidbody>().velocity = velocity;

        diameter = Convert.ToSingle((double)BallInfo[FIELD_DIAMETER]);
    }
开发者ID:BahuMan,项目名称:MultiPong,代码行数:16,代码来源:PongBall.cs

示例9: Caminar

    void Caminar(Rigidbody player, List<Vector2> listaCamino)
    {
        if (listaCamino.Count != 0 )
        {
            GetComponent<LineRenderer>().SetColors(Color.clear, Color.clear);
            Vector3 proximoPunto = new Vector3(listaCamino[0].x, 0, listaCamino[0].y);
            //Vector3 fwd = player.transform.TransformDirection(proximoPunto);
            player.GetComponent<Rigidbody>().transform.position = proximoPunto;

            if (!gameController.repetir)
            {
                listaBackUp.Add(listaCamino[0]);
            }

            listaCamino.Remove(listaCamino[0]);

            /* RaycastHit elrasho = new RaycastHit();
             if (listaCamino.Count != 0 && Physics.Raycast(player.position, fwd, out elrasho, Vector2.Distance(player.position, new Vector3(listaCamino[0].x, 0, listaDePuntos[0].y))))
             {
                 if (elrasho.collider.tag == "Enemy")
                 {
                     print("asdfasdfa");
                     gameController.finNivel = true;
                     repetir = false;
                     animacion = false;
                     //listaDePuntos.RemoveRange(0,listaDePuntos.Count);
                 }
             }
             */
        }
        else
        {
            if (gameController.palosGolf <= 1)
            {
                gameController.audioLose.Play();
                gameController.mensaje = "You didnt reach the goal!";
                gameController.finNivel = true;
            }
            else
            {
                gameController.palosGolf -= 1;
            }
        }
    }
开发者ID:TapTapTapps,项目名称:WayPath,代码行数:44,代码来源:Dibujar.cs

示例10: braced

 public bool braced(Rigidbody body, Vector3 dir)
 {
     RaycastHit hit;
     Rigidbody rigidTarg = body.GetComponent<Rigidbody>();
     if (Physics.Raycast (body.position, dir, out hit, .51f)) {
         Rigidbody rigidBrace = hit.collider.attachedRigidbody;
         Debug.DrawRay(body.position, dir,Color.yellow);
         if(rigidBrace == null)
         {
             Debug.Log ("no rigidbody.");
             return true;
         }
         if(rigidBrace.mass + rigidTarg.mass > 1.5*(rb.mass))
         {
             Debug.Log ("Braced");
             return true;
         }
     }
     Debug.Log ("Not braced");
     return false;
 }
开发者ID:weebco,项目名称:i-make-shit-games,代码行数:21,代码来源:Kelsier.cs

示例11: Awake

    private void Awake()
    {
        cachedRigidbody = GetComponent<Rigidbody>();
        cachedCamera = GetComponentInChildren<Camera>();
        cachedPlayerCapsule = GetComponent<CapsuleCollider>();

        // create ghost player for jumping velocity
        var ghostPlayer = new GameObject("Ghost Player");
        ghostPlayer.AddComponent<CapsuleCollider>().height = cachedPlayerCapsule.height;
        ghostPlayerRB = ghostPlayer.AddComponent<Rigidbody>();
        ghostPlayer.transform.SetParent(transform);

        // set both of the capsule colliders to be similar
        cachedRigidbody.useGravity = ghostPlayerRB.useGravity = false;
        cachedRigidbody.constraints = ghostPlayerRB.constraints = RigidbodyConstraints.FreezeRotation;
        cachedRigidbody.interpolation = ghostPlayerRB.interpolation = RigidbodyInterpolation.Interpolate;
        cachedRigidbody.collisionDetectionMode = ghostPlayerRB.collisionDetectionMode = CollisionDetectionMode.Continuous;

        // adjust the camera height
        cachedCamera.transform.localPosition = new Vector3(0, 0.5f, 0);

        // make sure that the ghost collider doesn't interfere with the player collider
        Physics.IgnoreCollision(cachedPlayerCapsule, ghostPlayerRB.GetComponent<CapsuleCollider>());
    }
开发者ID:calebhc,项目名称:udon_player,代码行数:24,代码来源:Player.cs

示例12: Store

        public static void Store(Rigidbody rigidbody)
        {
            RigidbodySettingsHolder settingsHolder = rigidbody.GetComponent<RigidbodySettingsHolder>();
            if (settingsHolder == null)
            {
                settingsHolder = rigidbody.gameObject.AddComponent<RigidbodySettingsHolder>();
            }
            settingsHolder.Set(rigidbody);

            if (settingsHolder.settings.StoreCallback != null)
            {
                settingsHolder.settings.StoreCallback();
                settingsHolder.settings.StoreCallback = null;
            }
        }
开发者ID:Naphier,项目名称:NGTools,代码行数:15,代码来源:NGRigidbodyPauser.cs

示例13: ReferencePoint

 /// <summary>
 /// ReferencePoint 3D Constructor
 /// </summary>
 public ReferencePoint(Rigidbody body)
 {
     m_RigidBody3D = body;
     m_SphereCollider = body.GetComponent<SphereCollider>();
     m_Transform = body.transform;
     m_IsDummy = false;
 }
开发者ID:soluclea,项目名称:LoonaProject,代码行数:10,代码来源:JellySprite.cs

示例14: Update

    void Update()
    {
        //If the player health is <= 0, destroy the player
        if(playerHealth <= 0.0f){
            if(playerIsAlive){ //Test to see if the player health has just crossed below 0.0

                centerMessageController.UpdateCenterMessage("Press Tab to Restart");
                centerMessageController.FlashCenterMessageAfterSeconds(0.5f);

                playerWeaponChange = playerGO.GetComponent<PlayerWeaponChange>();

                dropPoint = playerWeaponChange.dropPoint.position;
                //Test to see if the dropPoint is being blocked by an obstacle...
                RaycastHit wallHit;
                if(Physics.Raycast (playerWeaponChange.transform.position, (dropPoint - playerWeaponChange.transform.position), out wallHit, (dropPoint - playerWeaponChange.transform.position).magnitude, 1 << LayerMask.NameToLayer("Environment_Collision"))){
                    dropPoint = playerWeaponChange.transform.position+(wallHit.point-playerWeaponChange.transform.position)*0.8f;
                }

                usableWeapons = GameObject.FindGameObjectWithTag(Tags.gameController).GetComponent<UsableWeapons>();

                if(playerWeaponChange.hasPrimaryWeap == true){
                    string equippedWeaponName = playerWeaponChange.primaryEquipped.gameObject.GetComponent<weaponIndex> ().weaponName;
                    int equippedWeaponIndex = usableWeapons.primaryUsableWeapons.IndexOf (equippedWeaponName);
                    dropWeapon = Instantiate(usableWeapons.worldPrimaryUsableWeapons [equippedWeaponIndex], dropPoint, playerWeaponChange.primarySpawnpoint.rotation) as Rigidbody;
                    dropWeapon.AddForce(playerGO.GetComponent<Rigidbody>().velocity*playerWeaponChange.dropForce);
                    dropWeapon.AddTorque (transform.up*playerWeaponChange.dropForce*Random.Range(-0.5f, 0.5f));
                    dropWeapon.GetComponent<weaponIndex>().ammoCount = playerWeaponChange.primaryEquipped.gameObject.GetComponent<weaponIndex> ().ammoCount;
                }
                if(playerWeaponChange.hasSecondaryWeap == true){
                    string equippedWeaponName = playerWeaponChange.secondaryEquipped.gameObject.GetComponent<weaponIndex> ().weaponName;
                    int equippedWeaponIndex = usableWeapons.secondaryUsableWeapons.IndexOf (equippedWeaponName);
                    dropWeapon = Instantiate(usableWeapons.worldSecondaryUsableWeapons [equippedWeaponIndex], dropPoint, playerWeaponChange.secondarySpawnpoint.rotation) as Rigidbody;
                    dropWeapon.AddForce(playerGO.GetComponent<Rigidbody>().velocity*playerWeaponChange.dropForce);
                    dropWeapon.AddTorque (transform.up*playerWeaponChange.dropForce*Random.Range(-0.5f, 0.5f));
                    dropWeapon.GetComponent<weaponIndex>().ammoCount = playerWeaponChange.secondaryEquipped.gameObject.GetComponent<weaponIndex> ().ammoCount;
                }
                deadBody = Instantiate (deadPlayer[damageTypeIndex], playerGO.transform.position, playerWeaponChange.primarySpawnpoint.rotation) as Rigidbody;

                //Check for helmet...
                if(deadBody.GetComponent<Animator>()){
                    Animator[] anims = playerGO.GetComponentsInChildren<Animator> ();
                    Animator deadBodyAnim = deadBody.GetComponent<Animator>();
                    foreach (Animator a in anims) {
                        AnimatorControllerParameter[] acps = a.parameters;
                        foreach (AnimatorControllerParameter acp in acps){
                            if(acp.name == "helmetEquipped"){
                                bool currentValue = a.GetBool ("helmetEquipped");
                                deadBodyAnim.SetBool ("helmetEquipped", currentValue);
                                break;
                            }
                        }
                    }
                    AnimatorControllerParameter[] deadBodyAcp = deadBodyAnim.parameters;
                    AnimatorControllerParameterType paramType = AnimatorControllerParameterType.Bool;
                    int randomIndex = 0;
                    while (paramType != AnimatorControllerParameterType.Trigger){
                        randomIndex = Random.Range (0, deadBodyAcp.Length); //Random.Range is exclusive for the 2nd value
                        paramType = deadBodyAcp[randomIndex].type;
                    }
                    deadBodyAnim.SetTrigger (deadBodyAcp [randomIndex].name);
                }
                //End check for helmet

                if(damageForce != Vector3.zero){
                    deadBody.AddForce (damageForce);
                }
                if(explosionForce != 0.0f){
                    //deadBody.AddExplosionForce(explosionForce, explosionLocation, explosionRadius);
                    deadBody.AddForce (explosionForce*((playerGO.transform.position - explosionLocation).normalized));
                }
            }
            playerIsAlive = false;
            Destroy(playerGO);

        }
    }
开发者ID:ScopatGames,项目名称:ShojiSplice,代码行数:76,代码来源:PlayerStats.cs

示例15: Recoil

 private void Recoil(Rigidbody ApplyForceTo, Vector3 AtPosition)
 {
     ApplyForceTo.GetComponent<Rigidbody>().AddForceAtPosition(-this.transform.up * recoilFactor , AtPosition);
 }
开发者ID:Mnemorie,项目名称:unifit,代码行数:4,代码来源:PistonMotion.cs


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