zoukankan      html  css  js  c++  java
  • 一个引力地球的范例

    using UnityEngine;
    using System.Collections;

    public class Magnetic : MonoBehaviour
    {
        public LayerMask m_MagneticLayers; //定义层
        public Vector3 m_Position; //定义向量
        public float m_Radius; //定义半径
        public float m_Force; //定义力学

        void FixedUpdate ()
        {
            Collider[] colliders; //定义一个COL
            Rigidbody rigidbody; //定义一个刚体

            colliders = Physics.OverlapSphere (transform.position + m_Position, m_Radius, m_MagneticLayers); //检测在m_Radius是否有COL相交 可以做某个半径的响应
            foreach (Collider collider in colliders)
            {
                rigidbody = (Rigidbody) collider.gameObject.GetComponent (typeof (Rigidbody));
                if (rigidbody == null)
                {
                    continue;
                }
                rigidbody.AddExplosionForce (m_Force * -1, transform.position + m_Position, m_Radius); //施加力
            }
        }

        void OnDrawGizmos() //绘制一个用于观察的虚拟体范围
        {
            Gizmos.color = Color.red;
            Gizmos.DrawWireSphere (transform.position + m_Position, m_Radius);
        }
    }

    /*
    var radius = 5.0;
    var power = 10.0;
    function Start ()
    {
     // Applies an explosion force to all nearby rigidbodies
     var explosionPos : Vector3 = transform.position;
     var colliders : Collider[] = Physics.OverlapSphere (explosionPos, radius);

     for (var hit : Collider in colliders)
     {
      if (!hit)
      continue;

      if (hit.rigidbody)
      hit.rigidbody.AddExplosionForce(power, explosionPos, radius, 3.0);
     }
    }
    */

  • 相关阅读:
    .NET Framework类库大概
    CTS、CLS、CIL与CLR
    .NETFramework、CLR、.NET Framework class library、托管代码是什么
    万维网三大核心技术
    Clang、GCC和LLVM是什么
    常见开源许可证、开源协议GPL、BSD、MIT、Mozilla、Apache和LGPL之间区别
    编译原理之变量、名字与标识符
    编译原理之静态策略与动态策略
    Jupyter Notebook打开任意文件
    修改VsCodes的语言为中文
  • 原文地址:https://www.cnblogs.com/softimagewht/p/1881660.html
Copyright © 2011-2022 走看看