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


C# Rigidbody2D.GetComponent方法代码示例

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


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

示例1: charge

 void charge()
 {
     numShots = 0;
     if (chargedShot==null) {
         charge_anim.SetBool("charge", true);
         chargedShot = Instantiate (gun.bullet, gun.firingLocation.position, Quaternion.identity) as Rigidbody2D;
         chargedShot.gameObject.SetActive(true);
         chargedCollider = chargedShot.GetComponent<CircleCollider2D>();
         chargedCollider.enabled = false;// disable the collider first
         script = chargedShot.GetComponent<BulletScript>(); // assign the script
         if (master.shipMode){
             chargedShot.rotation = 90; // 270 degrees means facing north
         }
         else {
             master.setCharge(1f); // set 'charging' layer to activate
         }
         chargedShot.GetComponent<SpriteRenderer>().enabled = false;
     } else { //if (chargeLevel<=totalCharge)
         Vector3 size = chargedShot.transform.localScale;
         chargedShot.transform.localScale = new Vector3(size.x*1.5f, size.y*1.5f, 1f);
         script.damage = script.damage*2;
     }
     // make the charged shot stronger
     chargeLevel++;
 }
开发者ID:Vylantze,项目名称:Chaos-Children,代码行数:25,代码来源:Charge.cs

示例2: Warp

	IEnumerator Warp(Rigidbody2D warper) {
		Vector2 newVel = warper.velocity;
		newVel.Normalize();
		newVel = warper.velocity.magnitude * link.transform.up;
		warper.GetComponent<SpriteRenderer>().enabled = false;
		warper.constraints = RigidbodyConstraints2D.FreezeAll;
		yield return new WaitForSeconds(warpTime);
		warper.GetComponent<SpriteRenderer>().enabled = true;
		warper.constraints = RigidbodyConstraints2D.None;
		warper.transform.position = link.transform.position;
		warper.velocity = newVel;
		warper.transform.rotation = link.transform.rotation;
	}
开发者ID:Ryan-Vacek,项目名称:BSUMars2,代码行数:13,代码来源:Portal.cs

示例3: Start

		// Use this for initialization
		void Start ()
		{
				RigidFrontWheel = frontWheel.GetComponent<Rigidbody2D> ();
				RigidRearWheel = rearWheel.GetComponent<Rigidbody2D> ();
				WjFrontWheel = RigidFrontWheel.GetComponent<WheelJoint2D> ();
				WjRearWheel = RigidRearWheel.GetComponent<WheelJoint2D> ();
		}
开发者ID:slehmann1,项目名称:purgatory,代码行数:8,代码来源:CarBehaviour.cs

示例4: DetachChunk

 void DetachChunk(Rigidbody2D chunk)
 {
     chunk.isKinematic = false;
     chunk.GetComponent<Collider2D>().enabled = true;
     chunk.angularVelocity = angularSpeed.Random() * Utils.RandomSign();
     chunk.velocity = new Vector2(horizontalForce.Random() * Utils.RandomSign(), verticalForce.Random());
 }
开发者ID:kitalkenhell,项目名称:KittenProject,代码行数:7,代码来源:DestructiblePlatform.cs

示例5: Update

	// Update is called once per frame
	void Update () {
		//RaycastHit2D hit = Physics2D.Raycast (transform.position, transform.up);
		//Debug.DrawLine (transform.position, hit.point);
		//laserHit.position = hit.point;
		if (stateMachine.getMovement() == CentralStateScript.Movement.Flight) {
			lineRenderer.enabled = false;
		} else if (stateMachine.getMovement() == CentralStateScript.Movement.Orbit) {
			lineRenderer.enabled = true;
		}

		if (UFO == null) {
			UFO = GameObject.FindGameObjectWithTag ("Player").GetComponent<Rigidbody2D> ();
			if (UFO == null) {
				return;
			}
			playerController = UFO.GetComponent<NewPlayerController> ();
		}
		transform.position = UFO.position + playerController.BurstDirecton;
		laserHit.position = (Vector2)transform.position + playerController.BurstDirecton / 10;
		lineRenderer.SetPosition (0, transform.position);
		lineRenderer.SetPosition (1, laserHit.position);
		/*direction.transform.position = laserHit.position;
		Quaternion rotation = Quaternion.LookRotation(playerController.BurstDirecton.normalized);
		rotation.x = 0f;
		rotation.y = 0f;
		direction.transform.rotation = rotation;*/
		//direction.transform.rotation = Quaternion.LookRotation(playerController.BurstDirecton.normalized) * _facing;

	}
开发者ID:waynchi,项目名称:GravityHop,代码行数:30,代码来源:lineCast.cs

示例6: nutGenerate

 IEnumerator nutGenerate()
 {
     yield return new WaitForSeconds (1f);
     rd = (Rigidbody2D)Instantiate (rd, transform.position, transform.rotation);
     rd.GetComponent<PolygonCollider2D> ().enabled = true;
     rd.isKinematic = false;
     done = true;
     //yield return new WaitForSeconds (1f);
 }
开发者ID:diglungdig,项目名称:GameDevelopmentWei,代码行数:9,代码来源:nutGenerator.cs

示例7: OnStartLocalPlayer

 public override void OnStartLocalPlayer()
 {
     base.OnStartLocalPlayer();
     body = GetComponent<Rigidbody2D>();
     anim = GetComponent<Animator>();
     netTransform = GetComponent<NetworkTransform>();
     groundCheck = transform.Find("groundCheck");
     heroAudSrc = body.GetComponent<AudioSource>();
 }
开发者ID:hrajagop,项目名称:2DShooter,代码行数:9,代码来源:HeroController.cs

示例8: Start

    /*---------------------------------------------------------------------------------------------------------------------
    -- FUNCTION: Start
    --
    -- DATE: March 9, 2016
    --
    -- REVISIONS: 
    --          April 4, 2016 - Hank Lo: Balance changes, numbers fixed.
    --          April 5, 2016 - Hank Lo: Balance changes, numbers fixed more.
    --
    -- DESIGNER: Hank Lo, Allen Tsang
    --
    -- PROGRAMMER: Hank Lo, Allen Tsang
    --
    -- INTERFACE: void Start(void)
    --
    -- RETURNS: void
    --
    -- NOTES:
    -- Function that's called when the script is first executed - it initializes all required values
    ---------------------------------------------------------------------------------------------------------------------*/
    new void Start()
    {
        cooldowns = new float[2] { 0.75f, 4 };

        healthBar = transform.GetChild(0).gameObject.GetComponent<HealthBar>();
        _classStat = new PlayerBaseStat(playerID, healthBar);
        _classStat.MaxHp = 1200;
		_classStat.MoveSpeed = 7;
		Debug.Log ("[DEBUG2] Setting Ninja Speed: " + _classStat.MoveSpeed);
        _classStat.AtkPower = 80;
        _classStat.Defense = 60;

        base.Start();

        sword = (Rigidbody2D)Resources.Load("Prefabs/NinjaSword", typeof(Rigidbody2D));
        teleport = (GameObject)Resources.Load("Prefabs/NinjaTeleport", typeof(GameObject));

        attack = (Rigidbody2D)Instantiate(sword, transform.position, transform.rotation);
        attack.GetComponent<BoxCollider2D>().enabled = false;

        attackMelee = attack.GetComponent<Melee>();
        attackMelee.playerID = playerID;
        attackMelee.teamID = team;
        attackMelee.damage = ClassStat.AtkPower;
        attack.transform.parent = transform;

        var controller = Resources.Load("Controllers/ninjaboi") as RuntimeAnimatorController;
        gameObject.GetComponent<Animator>().runtimeAnimatorController = controller;

        //Player specific initialization
        if (playerID == GameData.MyPlayer.PlayerID)
        {
            //Starting item kit
            Inventory.instance.AddItem(1);
        }

        //ninja attack sound
        au_simple_attack = Resources.Load("Music/Weapons/ninjaboi_sword_primary") as AudioClip;
        au_special_attack = Resources.Load("Music/Weapons/ninjaboi_teleport") as AudioClip;

		Debug.Log ("[DEBUG] Setting Ninja Speed After Calling Base: " + _classStat.MoveSpeed);
    }
开发者ID:CarsonRoscoe,项目名称:DefendAman,代码行数:62,代码来源:NinjaClass.cs

示例9: projectileInitiate

 IEnumerator projectileInitiate()
 {
     //generate new projectile
     yield return new WaitForSeconds (1f);
     rd = (Rigidbody2D)Instantiate (rd, transform.position, transform.rotation);
     rd.GetComponent<PolygonCollider2D> ().enabled = false;
     rd.transform.parent = transform;
     rd.transform.localPosition = new Vector3 (1.4f, 0f, 0f);
     rd.transform.localScale = new Vector3 (1f, 1f, 1f);
     rd.isKinematic = true;
 }
开发者ID:diglungdig,项目名称:GameDevelopmentWei,代码行数:11,代码来源:projectileShooting.cs

示例10: GrabGoat

	//--------------------------------------------------------------------------------
	#region Private Methods
	
	void GrabGoat(Rigidbody2D goat) {
		this.goat = goat;
		Debug.Log("Got the goat!");
		goat.isKinematic = true;
		goat.MovePosition(transform.position);
		goat.GetComponent<Collider2D>().enabled = false;
		onGoatGrabbed.Invoke();
		CharController player = GetComponentInParent<CharController>();
		Goat.instance.lastCarry = player.playerNum;
		Alter.instance.CancelWin();
	}
开发者ID:lancetipton04,项目名称:VG,代码行数:14,代码来源:GoatGrabber.cs

示例11: Start

 // Use this for initialization
 void Start()
 {
     startingJoystickSpot = transform.position;
     joystickAppearanceThreshhold = .8f;
     joystickMaxThumbDist = 1.3f;
     distToThrow = .1f;
     joystickFinger = -1;
     spearFinger = -2;
     moveForce = 10f;
     jaiScript = GameObject.Find ("Jai").GetComponent<Jai> ();
     controlStickSprite = GameObject.Find ("ControlStick").GetComponent<SpriteRenderer>();
     jaiTransform = jaiScript.transform;
     balloonBasketBody = GameObject.Find ("BalloonBasket").GetComponent<Rigidbody2D>();
     //correctionPixels = new Vector2 (Screen.width/2,-Screen.height/2);
     correctionPixels = new Vector2 (560,-960); //half of the screen width is 560 and yeah the heights weird [1280-640]
     //correctionPixelFactor = 5 / Screen.height;
     correctionPixelFactor = 5f / 320f; //5 game units divided by 320 pixels
     maxBalloonSpeed = balloonBasketBody.GetComponent<BalloonBasket>().maxBalloonSpeed;
 }
开发者ID:briveramelo,项目名称:Sky,代码行数:20,代码来源:Joyfulstick.cs

示例12: ReferencePoint

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

示例13: PreformEvent

    public int PreformEvent(Rigidbody2D Body, int Speed, Animator Anim, int EventNumber, double X_Original, double Y_Original, int CaseStep)
    {
        //SavePosition(Body.gameObject.name);  //<---- For saving an AI's location

        //Var for AI x and y
        float XMove = 0;
        float YMove = 0;

        if (X_Cutscene != 0 && Y_Cutscene != 0)
        {
            XMove = Find_X_Distance(Body, X_Cutscene);
            YMove = Find_Y_Distance(Body, Y_Cutscene);

            if (XMove == 0 && YMove == 0)
            {
                CaseStep++;
                GetLocation(Body, EventNumber, CaseStep);
                SaveInfo(Body, EventNumber, CaseStep);
            }

        }
        else
        {
            #region CutScene Finished
            Body.GetComponent<AI_Character>().Action = AI_Character.AI_Action.StationaryWithDir;
            Body.GetComponent<CircleCollider2D>().enabled = true;

            //---Check for teleport---
            //Read in SaveGame.xml
            XmlDocument SaveGameDoc = new XmlDocument();
            SaveGameDoc.LoadXml(Resources.Load("CutScenes/CutSceneEvents").ToString());

            foreach (XmlNode node in SaveGameDoc.SelectNodes("CutSceneEvents/Scenes/Scene"))
            {
                if (Application.loadedLevelName == node.SelectSingleNode("SceneName").InnerText)
                {
                    if (Body.name == "AI Josh")
                    {
                        #region AI Josh
                        //Check for teleport
                        if (node.SelectSingleNode("Part" + EventNumber + "/Teleport/JoshAI/X").InnerText != "" && node.SelectSingleNode("Part" + EventNumber + "/Teleport/JoshAI/Y").InnerText != "")
                        {
                            Body.GetComponent<Transform>().position = new Vector3(float.Parse(node.SelectSingleNode("Part" + EventNumber + "/Teleport/JoshAI/X").InnerText), float.Parse(node.SelectSingleNode("Part" + EventNumber + "/Teleport/JoshAI/Y").InnerText));
                        }

                        //Read in SaveGame.xml
                        XmlDocument xSaveGameDoc = new XmlDocument();
                        xSaveGameDoc.LoadXml(DoSaveGame.FetchSaveData());

                        //Find current scene then find ScenePart.
                        foreach (XmlNode Xnode in xSaveGameDoc.SelectNodes("SaveData/SaveState/Scenes/Scene"))
                        {
                            if (Application.loadedLevelName == Xnode.SelectSingleNode("SceneName").InnerText)
                            {
                                Xnode.SelectSingleNode("AI/JoshAI/X").InnerText = Body.position.x.ToString();
                                Xnode.SelectSingleNode("AI/JoshAI/Y").InnerText = Body.position.y.ToString();
                                Xnode.SelectSingleNode("AI/JoshAI/Action").InnerText = "";
                                Xnode.SelectSingleNode("AI/JoshAI/EventType").InnerText = "";
                                Xnode.SelectSingleNode("AI/JoshAI/CaseStep").InnerText = "";

                                break;
                            }
                        }

                        //Save XML
                        DoSaveGame.UpdateSaveData(xSaveGameDoc);

                        #endregion
                    }
                    else if (Body.name == "AI Matt")
                    {
                        #region AI Matt

                        //Check for teleport
                        if (node.SelectSingleNode("Part" + EventNumber + "/Teleport/MattAI/X").InnerText != "" && node.SelectSingleNode("Part" + EventNumber + "/Teleport/MattAI/Y").InnerText != "")
                        {
                            Body.GetComponent<Transform>().position = new Vector3(float.Parse(node.SelectSingleNode("Part" + EventNumber + "/Teleport/MattAI/X").InnerText), float.Parse(node.SelectSingleNode("Part" + EventNumber + "/Teleport/MattAI/Y").InnerText));
                        }

                        //Read in SaveGame.xml
                        XmlDocument xSaveGameDoc = new XmlDocument();
                        xSaveGameDoc.LoadXml(DoSaveGame.FetchSaveData());

                        //Find current scene then find ScenePart.
                        foreach (XmlNode Xnode in xSaveGameDoc.SelectNodes("SaveData/SaveState/Scenes/Scene"))
                        {
                            if (Application.loadedLevelName == Xnode.SelectSingleNode("SceneName").InnerText)
                            {
                                Xnode.SelectSingleNode("AI/MattAI/X").InnerText = Body.position.x.ToString();
                                Xnode.SelectSingleNode("AI/MattAI/Y").InnerText = Body.position.y.ToString();
                                Xnode.SelectSingleNode("AI/MattAI/Action").InnerText = "";
                                Xnode.SelectSingleNode("AI/MattAI/EventType").InnerText = "";
                                Xnode.SelectSingleNode("AI/MattAI/CaseStep").InnerText = "";
                            }
                        }

                        //Save XML
                        DoSaveGame.UpdateSaveData(xSaveGameDoc);

                        #endregion
//.........这里部分代码省略.........
开发者ID:PeasB,项目名称:Unity-Game,代码行数:101,代码来源:AI_Events.cs

示例14: Store

 public static void Store(Rigidbody2D rigidbody)
 {
     Rigidbody2DSettingsHolder settingsHolder = rigidbody.GetComponent<Rigidbody2DSettingsHolder>();
     if (settingsHolder == null)
     {
         settingsHolder = rigidbody.gameObject.AddComponent<Rigidbody2DSettingsHolder>();
     }
     settingsHolder.Set(rigidbody);
 }
开发者ID:Naphier,项目名称:NGTools,代码行数:9,代码来源:NGRigidbodyPauser.cs

示例15: Restore

 public static void Restore(Rigidbody2D rigidbody)
 {
     Rigidbody2DSettingsHolder settingsHolder = rigidbody.GetComponent<Rigidbody2DSettingsHolder>();
     if (settingsHolder != null)
     {
         rigidbody.isKinematic = settingsHolder.settings.isKinematic;
         rigidbody.velocity = settingsHolder.settings.velocity;
         rigidbody.angularVelocity = settingsHolder.settings.angularVelocity;
         rigidbody.mass = settingsHolder.settings.mass;
         rigidbody.drag = settingsHolder.settings.linearDrag;
         rigidbody.angularDrag = settingsHolder.settings.angularDrag;
         rigidbody.gravityScale = settingsHolder.settings.gravityScale;
         rigidbody.interpolation = settingsHolder.settings.interpolate;
         rigidbody.collisionDetectionMode = settingsHolder.settings.collisionDetection;
         rigidbody.sleepMode = settingsHolder.settings.sleepMode;
         rigidbody.constraints = settingsHolder.settings.constraints;
         Object.Destroy(settingsHolder);
     }
     else
         Debug.LogError("Cannot restore rigidbody (" + rigidbody.name + ")! No settings holder found");
 }
开发者ID:Naphier,项目名称:NGTools,代码行数:21,代码来源:NGRigidbodyPauser.cs


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