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


C# Rigidbody2D.AddTorque方法代码示例

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


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

示例1: Start

	void Start() {
		aiai = GetComponent<Rigidbody2D> ();

		Vector2 dytt = new Vector2 (Random.Range (-100.0f, 100.0f),
			               			Random.Range (-100.0f, 100.0f));
		
		aiai.AddTorque(Random.Range(-100.0f, 100.0f));
		aiai.AddForce (dytt, ForceMode2D.Impulse);
	}
开发者ID:monkeybits,项目名称:ggj2016chocolate,代码行数:9,代码来源:TextSuccessScript.cs

示例2: Die

 public virtual void Die(Rigidbody2D rb)
 {
     rb.fixedAngle = false;
     //		rb.AddForce (new Vector2(Random.Range(3,4),Random.Range(40,80)));
     //		rb.AddForce (new Vector2(4,50f));
     rb.gravityScale = 7;
     rb.AddTorque(30f);
     gameObject.GetComponent<CircleCollider2D> ().isTrigger = true;
     //		Invoke ("DestroyObject",5f);
 }
开发者ID:davybolivar,项目名称:Blockade,代码行数:10,代码来源:EnemyClass.cs

示例3: OnEnable

    public override void OnEnable()
    {
        base.OnEnable();
        m_rigidbody2D = GetComponent<Rigidbody2D>();
        m_rigidbody2D.AddTorque(Random.Range(-100, 100));
        CurrentHealth = MaxHealth;

        if(sprites.Length > 0)
            GetComponent<SpriteRenderer>().sprite = sprites[Random.Range(0, sprites.Length)];
    }
开发者ID:Jamroah,项目名称:AsteroidsClone,代码行数:10,代码来源:Asteroid.cs

示例4: Start

 // Use this for initialization
 void Start()
 {
     // Set random motion at start.
     float torque = Random.Range(100, 1000);
     float sign = Mathf.Sign(Random.value - 0.5f);
     Vector2 vector = Random.insideUnitCircle;
     _rigidbody = GetComponent<Rigidbody2D>();
     _rigidbody.AddTorque(torque * sign, ForceMode2D.Force);
     _rigidbody.AddForce(vector * 100, ForceMode2D.Force);
 }
开发者ID:MickPlaYer,项目名称:PinBallRPG,代码行数:11,代码来源:ItemBall.cs

示例5: Start

    // Use this for initialization
    void Start()
    {
        attitudeControllers = new List<GameObject>();
        physicsBody = GetComponent<Rigidbody2D>();

        physicsBody.AddTorque(10000);

        foreach (Transform child in transform) {
            if (child.gameObject.name == "Attitude") {
                attitudeControllers.Add(child.gameObject);
            }
        }
    }
开发者ID:Bloodyaugust,项目名称:fabricatorstation,代码行数:14,代码来源:ShipController.cs

示例6: Start

    // Use this for initialization
    void Start()
    {
        r2d = GetComponent<Rigidbody2D>();

        r2d.AddForce(-Vector2.right.Rotate(Random.Range(-minYAngle, -maxYAngle)) * Random.Range(minImpulse, maxImpulse), ForceMode2D.Impulse);
        r2d.AddTorque(Random.Range(minTorque, maxTorque));

        startY = transform.position.y;
        gravity = true;

        if (sprites != null && sprites.Length > 0)
        {
            GetComponent<SpriteRenderer>().sprite = Random2.RandomArrayElement(sprites);
        }
    }
开发者ID:gorecode,项目名称:they-will-burn,代码行数:16,代码来源:FlyingEnemyHead.cs

示例7: Start

    void Start()
    {
        m_randomOffset = Random.Range(0.0f, 1.0f);
        float parenty = transform.parent.localPosition.y;

        m_targetY = Random.Range(transform.localPosition.y - 2.0f, transform.localPosition.y);

        if(m_targetY + parenty > -2.0f)
        {
            m_targetY = Random.Range(-10.0f - parenty, -4.0f - parenty);
        }

        m_rigidbody = GetComponent<Rigidbody2D>();
        m_rigidbody.AddForce(new Vector2(Random.Range(-10.0f, 10.0f), Random.Range(1.0f, 10.0f)), ForceMode2D.Impulse);
        m_rigidbody.AddTorque(Random.Range(10.0f, 100.0f));
    }
开发者ID:AndyGates,项目名称:ReleaseTheKraken,代码行数:16,代码来源:BoatPart.cs

示例8: Awake

 void Awake()
 {
     hpScript = GetComponent<HealthScript> ();
     sprite = GetComponent<SpriteRenderer> ();
     player = GameObject.FindGameObjectWithTag ("Player");
     WorldGen = GameObject.Find ("WorldGenerator").GetComponent<WorldGenerator>();
     float size = Random.Range (minSize, maxSize);
     float torque = Random.Range (minTorque, maxTorque);
     float force = Random.Range (minForce, maxForce);
     transform.Rotate(0.0f, 0.0f, Random.Range(0.0f, 360.0f));
     transform.localScale = new Vector3 (size, size, size);
     rb = GetComponent<Rigidbody2D> ();
     rb.mass = size * 2000;
     rb.AddTorque (torque, ForceMode2D.Impulse);
     rb.AddForce (transform.up * force, ForceMode2D.Impulse);
     hpScript.maxHp = Mathf.RoundToInt(30 * size);
     hpScript.hp = Mathf.RoundToInt(hpScript.maxHp - Random.Range (0, hpScript.maxHp));
 }
开发者ID:JasonSlingsCode,项目名称:SPACESHIPGAME,代码行数:18,代码来源:AsteroidAI.cs

示例9: OnTriggerEnter2D

	void OnTriggerEnter2D(Collider2D other) {
		//DEAD DEBUG BELOW
		if (other.gameObject.tag == "Goal") {
			goalHit=true;
			GameObject.FindWithTag("Timer").GetComponent<Timer>().Stop();
			if(useHelmet){
				GameObject.FindWithTag("Helmet").SetActive(false);
			}
			GetComponent<PinguNoises>().shouldMakeSound = false;
			GetComponent<OlafSigh>().dead = true;
			GameObject.FindWithTag("JetPackSounds").GetComponent<JetpackSound>().levelDone = true;
		}
		if (other.gameObject.tag == "Laser" && debug == false) {
			//play explosions and 2 sec later restart? feels nice with insta restart. mby sound
			Dead();
			
		}

		//Activate Physics objects
		if (other.gameObject.tag == "PhysicsObject" && other.GetComponent<Rigidbody2D>().isKinematic == true) {
			pObjectToActivate = other.GetComponent<Rigidbody2D>();
			pObjectToActivate.isKinematic = false;
			torqueToAdd = UnityEngine.Random.Range(-7f, 7f);
			pObjectToActivate.AddTorque(torqueToAdd, ForceMode2D.Force);
		}
		
		if (other.gameObject.tag == "Fuel") {		
			Fuel += 100;
			Destroy (other.gameObject);
			print ("FEUL DAMNIT");

			if (Fuel > maxFuel)
				Fuel = maxFuel;
		} 
		if (other.gameObject.tag == "ZoneHide") {
			detectable = false;
			print("HIDE");
		}/*
		else if (other.gameObject.tag == "Bouncer") {
			//bounces pingu
			Vector2 pos= new Vector2(0,0);
			pos.x = Mathf.Abs(rigidbody2D.position.x) - Mathf.Abs(other.transform.position.x);
			pos.y = Mathf.Abs(rigidbody2D.position.y) - Mathf.Abs(other.transform.position.y);
			
			if(Mathf.Abs(pos.x)<Mathf.Abs(pos.y)){
				print ("ByttY");
				print (rigidbody2D.velocity.y);
				Vector2 v =rigidbody2D.velocity;
				v.y = Mathf.Round(rigidbody2D.velocity.y);
				v.y = -v.y;
				if(v.y>0 && v.y<7.0f)
					v.y=8.3f;
				else if(v.y<0 && v.y>-7.0f)
					v.y=-8.3f;
				rigidbody2D.velocity = v;
				
				print (rigidbody2D.velocity.y);
			}

			else if(Mathf.Abs(pos.x)>Mathf.Abs(pos.y)){
				Vector2 v = rigidbody2D.velocity;
				v.x = Mathf.Round(rigidbody2D.velocity.x);
				v.x = -v.x;
				if(v.x>0 && v.x<7.0f)
					v.y=8.3f;
				else if(v.x<0 && v.x>-7.0f)
					v.y=-8.3f;
				rigidbody2D.velocity = v;
				print ("ByttX");
			}
			else{
				Vector2 v = rigidbody2D.velocity;
				v = -v;
				rigidbody2D.velocity = v;
			}
		}*/
	}
开发者ID:PetterV,项目名称:Flight-of-the-Penguin,代码行数:77,代码来源:Movement.cs

示例10: Start

	// Use this for initialization
	void Start () {
		myRigidBody = GetComponent<Rigidbody2D>();
		myRigidBody.AddRelativeForce(Vector3.right * projectileSpeed);
		myRigidBody.AddTorque(torque);
	}
开发者ID:Greg-Rus,项目名称:HomoPropaganda,代码行数:6,代码来源:ProjectileMovement.cs

示例11: Start

    // Use this for initialization
    void Start()
    {
        incol = false;
        invis = false;

        mainstate = GameObject.FindGameObjectWithTag ("GameController").GetComponent<GameController> ();

        curasteroidstate = GetComponentInParent<AsteroidManager> ();
        curRig = GetComponent<Rigidbody2D> ();

        // Scaling
        // Get main camera component
        main = Camera.main;
        // Main camera height and width
        camheight = main.orthographicSize * 2;
        camwidth = camheight * main.aspect;
        // Set temp to ship sprite
        temp = GetComponent<SpriteRenderer> ().sprite;
        // How big bg1 is in world units
        unitWidth = temp.textureRect.width / temp.pixelsPerUnit;
        //unitHeight = temp.textureRect.height / temp.pixelsPerUnit;

        // Asteroid Details
        randomscale = Random.Range (7, 12);
        speed.x = 0;
        speed.y = Random.Range (curasteroidstate.speedmin, curasteroidstate.speedmax);
        turnspeed = Random.Range (-4, 4);

        // Scale ship according to camera size
        transform.localScale = new Vector3 (camwidth / (unitWidth * randomscale), camwidth / (unitWidth * randomscale));

        //Asteroid Initial speeds
        curRig.velocity = speed;
        curRig.AddTorque (turnspeed);
    }
开发者ID:yuhang174,项目名称:Light-Speed,代码行数:36,代码来源:AsteroidMovement.cs

示例12: Start

    // Use this for initialization
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();

        // Create some states
        stateFree = AddState ("Free");
        stateCaptured = AddState ("Captured");
        stateFlushed = AddState ("Flushed");

        StartState.AddTransition (stateFree).AddTransition (stateCaptured).AddTransition (stateFlushed);

        // Get a list of all audio sources on children
        audioSources = new Dictionary<string, AudioSource> ();
        foreach (AudioSource s in GetComponentsInChildren<AudioSource> ()) {
            audioSources.Add (s.gameObject.name, s);
        }

        Transition (stateFree);

        // Apply a random velocity to the ball
        rb.velocity = new Vector2 (Random.value * 3, Random.value * 3);
        rb.AddTorque(Random.Range(1,3));
    }
开发者ID:saltatory,项目名称:unity-fsm,代码行数:24,代码来源:Thingy.cs

示例13: Start

    private void Start()
    {
        _Rigidbody = GetComponent<Rigidbody2D>();
        float magnitude = Random.Range (MinForce, MaxForce);
        float x = Random.Range (-1f, 1f);
        float y = Random.Range (-1f, 1f);

        _Rigidbody.AddForce (magnitude * new Vector2 (x,y));

        float torque = Random.Range (MinTorque, MaxTorque);
        _Rigidbody.AddTorque (torque);

        // TO-DO: complete this class
    }
开发者ID:NitCoin,项目名称:gamedev-assignment-03-master-asteroids,代码行数:14,代码来源:Asteroid.cs


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