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


C# BoxCollider类代码示例

本文整理汇总了C#中BoxCollider的典型用法代码示例。如果您正苦于以下问题:C# BoxCollider类的具体用法?C# BoxCollider怎么用?C# BoxCollider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: Start

    // Use this for initialization
    void Start()
    {
        oCol = GetComponent<BoxCollider>();
        t = transform;

        normColSize = oCol.size.x;

        float hori = oCol.size.x * t.localScale.x;
        float vert = oCol.size.y * t.localScale.y;

        float hMargin = Mathf.Min(margin, hori / minMarginDividor);
        float vMargin = Mathf.Min(margin, vert / minMarginDividor);

        topCol = Instantiate(Resources.Load("colliders/top"), t.position + new Vector3(hMargin, vert - vMargin, 0), t.rotation) as GameObject;
        botCol = Instantiate(Resources.Load("colliders/bot"), t.position + new Vector3(hMargin, 0, 0), t.rotation) as GameObject;
        rightCol = Instantiate(Resources.Load("colliders/right"), t.position + new Vector3(hori - hMargin, 0, 0), t.rotation) as GameObject;
        leftCol = Instantiate(Resources.Load("colliders/left"), t.position, t.rotation) as GameObject;

        topCol.transform.localScale = new Vector3(t.localScale.x - hMargin*2/normColSize, vMargin/normColSize, t.localScale.z);
        botCol.transform.localScale = new Vector3(t.localScale.x - hMargin*2/normColSize, vMargin/normColSize, t.localScale.z);
        rightCol.transform.localScale = new Vector3(hMargin/normColSize, t.localScale.y, t.localScale.z);
        leftCol.transform.localScale = new Vector3(hMargin/normColSize, t.localScale.y, t.localScale.z);

        Destroy(gameObject);
    }
开发者ID:TimuSumisu,项目名称:recess-race,代码行数:26,代码来源:CollisionGenerator.cs

示例2: ClosestPointOnSurface

    public static Vector3 ClosestPointOnSurface(BoxCollider collider, Vector3 to)
    {
        // Cache the collider transform
        var ct = collider.transform;

        // Firstly, transform the point into the space of the collider
        var local = ct.InverseTransformPoint(to);

        // Now, shift it to be in the center of the box
        local -= collider.center;

        // Clamp the points to the collider's extents
        var localNorm =
            new Vector3(
                Mathf.Clamp(local.x, -collider.size.x * 0.5f, collider.size.x * 0.5f),
                Mathf.Clamp(local.y, -collider.size.y * 0.5f, collider.size.y * 0.5f),
                Mathf.Clamp(local.z, -collider.size.z * 0.5f, collider.size.z * 0.5f)
            );

        // Select a face to project on
        if (Mathf.Abs(localNorm.x) > Mathf.Abs(localNorm.y) && Mathf.Abs(localNorm.x) > Mathf.Abs(localNorm.z))
            localNorm.x = Mathf.Sign(localNorm.x) * collider.size.x * 0.5f;
        else if (Mathf.Abs(localNorm.y) > Mathf.Abs(localNorm.x) && Mathf.Abs(localNorm.y) > Mathf.Abs(localNorm.z))
            localNorm.y = Mathf.Sign(localNorm.y) * collider.size.y * 0.5f;
        else if (Mathf.Abs(localNorm.z) > Mathf.Abs(localNorm.x) && Mathf.Abs(localNorm.z) > Mathf.Abs(localNorm.y))
            localNorm.z = Mathf.Sign(localNorm.z) * collider.size.z * 0.5f;

        // Now we undo our transformations
        localNorm += collider.center;

        // Return resulting point
        return ct.TransformPoint(localNorm);
    }
开发者ID:renokun,项目名称:SuperCharacterController,代码行数:33,代码来源:SuperCollider.cs

示例3: Awake

 void Awake()
 {
     // Set up references.
     playerRigidbody = GetComponent <Rigidbody> ();
     Physics.IgnoreLayerCollision(8, 15, true);
     boxCol = GetComponent<BoxCollider>();
 }
开发者ID:Stuxles,项目名称:NHL-Y1-S2,代码行数:7,代码来源:PlayerController.cs

示例4: Awake

    void Awake()
    {
        m_relatedCam = GameObject.Find("MogoMainUI").transform.GetChild(0).GetComponentInChildren<Camera>();
        m_relatedCollider = transform.GetComponentInChildren<BoxCollider>();

        m_rayHit = new RaycastHit();
    }
开发者ID:lbddk,项目名称:ahzs-client,代码行数:7,代码来源:InsetUIPackageGrid.cs

示例5: Start

    void Start()
    {


        if(isInverted)
        {
            Vector3 theScale = transform.localScale;
            theScale.x *= -1;
            transform.localScale = theScale;
        }
        collider = gameObject.GetComponent<BoxCollider>();
        gameObject.GetComponent<Animator>().SetBool("Open",opened);

        if (opened){
            gameObject.GetComponent<Animator>().Play("AlreadyOpenHor");
            gameObject.GetComponent<Animator>().Play("AlreadyOpenVer");
            collider.enabled = false;

                
        }
        else
        {
            gameObject.GetComponent<Animator>().Play("AlreadyCloseHor");
            gameObject.GetComponent<Animator>().Play("AlreadyCloseVer");
            collider.enabled = true;
            
        }

        
    }
开发者ID:DanielParra159,项目名称:GGJ2016,代码行数:30,代码来源:Door.cs

示例6: OnDisable

 void OnDisable()
 {
     print( "Awake Box spawn area" );
     spawnArea = GetComponent<BoxCollider>();
     spawnArea.isTrigger = true;
     base.OnDisable();
 }
开发者ID:MashGames,项目名称:Flourny,代码行数:7,代码来源:CubeAreaSpawner.cs

示例7: SpawnObjects

    /// <summary>
    /// Spawns random objects within the box collider bounds.
    /// </summary>
    public void SpawnObjects()
    {
        CurrentSpawnedObjects = new GameObject[NumberToSpawn];
        Bounds = GetComponent<BoxCollider>();

        for (int i = 0; i < NumberToSpawn; i++)
        {
            // Get random position within this transform.
            Vector3 rndPosWithin = new Vector3(Random.Range(-1f, 1f) * Bounds.size.x / 2,
                                               Random.Range(-1f, 1f) * Bounds.size.x / 2,
                                               Random.Range(-1f, 1f) * Bounds.size.z / 2);
            rndPosWithin += transform.position;

            if (!isObjectTooClose(rndPosWithin))
            {
                GameObject spawnedObject = (GameObject)Instantiate(ObjectSpawnPrefabs[Random.Range(0, ObjectSpawnPrefabs.Length)], rndPosWithin, Quaternion.identity);
                CurrentSpawnedObjects[i] = spawnedObject;
                CurrentSpawnedObjects[i].transform.parent = transform;

                // Create a child game object, which we will attach the culling sphere to.
                GameObject cullingSphere = new GameObject("Culling Sphere");
                cullingSphere.transform.position = rndPosWithin;
                cullingSphere.transform.parent = spawnedObject.transform;

                // We use a sphere collider to determine whether the object should be rendered.
                SphereCollider spawnCollider = cullingSphere.AddComponent<SphereCollider>();
                spawnCollider.radius = hideSpawnedObjectDistance;

                // The CullObject script determines whether to show or hide the object.
                CullObject spawnCuller = cullingSphere.AddComponent<CullObject>();
                spawnCuller.CullingTarget = CullingTarget;

            }
        }
    }
开发者ID:coppermind,项目名称:Impulse,代码行数:38,代码来源:ObjectSpawner.cs

示例8: Start

    new void Start()
    {
        base.Start ();

        AOECollider = muzzlePoint.GetComponent<BoxCollider> ();
        AOECollider.size = colliderDisableSize;
    }
开发者ID:kostya05,项目名称:TPS-Proto-Unity,代码行数:7,代码来源:ContiniusGun.cs

示例9: Start

 // Use this for initialization
 void Start()
 {
     // Reference objects
     this.pickUp = gameObject.GetComponent<AudioSource>();
     this._renderer = gameObject.GetComponent<Renderer>();
     this.boxCollider = gameObject.GetComponent<BoxCollider>();
 }
开发者ID:Silhoualice,项目名称:3D-First-Person-Shooter,代码行数:8,代码来源:CoinCollect.cs

示例10: Start

 private void Start()
 {
     this.rb = base.GetComponent<Rigidbody>();
     this.col = base.GetComponent<BoxCollider>();
     base.StartCoroutine("doMove");
     this.val = UnityEngine.Random.Range(-50f, 50f);
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:7,代码来源:testMove.cs

示例11: Start

 // Use this for initialization
 void Start()
 {
     _camera = Camera.main;
     amountToMove = Vector3.zero;
     _stats = new playerStats();
     _collider = transform.GetComponent<BoxCollider>();
 }
开发者ID:KvltKitty,项目名称:Space,代码行数:8,代码来源:playerController.cs

示例12: Awake

 void Awake()
 {
     Debug.Log ("Zombie instantiated!");
     moveSpeed = 250f;
     isIdle = true;
     ChaseTarget = null;
     transforming = false;
     idleCounter = 0;
     idleCounterMax = 3f;
     idleMoveSpeed = 50f;
     targetContact = false;
     zombieSlowBy = 20;
     transforming = false;
     maxTransformTime = 1.5f;
     transformTime = maxTransformTime;
     idleSoundIndex = Random.Range(0, idle.Length);
     alertSoundIndex = Random.Range(0, alert.Length);
     zombieDeathIndex = Random.Range(0,zombieDeath.Length);
     //Enables idle zombies to 'see' humans and the player
     BoxOfSight = (BoxCollider)transform.GetComponent(typeof(BoxCollider));
     BoxOfSight.enabled = true;
     /* BUG
      * Player.laser will collide with BoxOfSight.
      * Attempted to assign BoxOfSight.layer = 2 (ignore raycast)
      * Could not assign layer to component, assigned to gameobject instead
      * Effect: player.laser will not collide with zombies (including BoxOfSight)
      */
     BoxOfSight.gameObject.layer = 2;
     gameManager = (GameManager)GameObject.Find ("GameManager").GetComponent("GameManager");
 }
开发者ID:explosivose,项目名称:projectx,代码行数:30,代码来源:ZombieMove.cs

示例13: Awake

    void Awake() {
        BoxRef = this.gameObject.AddComponent<BoxCollider>();
        ScriptRef = this.gameObject.GetComponent<CartoonExplosionFX>();
        ParentRef = this.gameObject.GetComponent<GameObject>();


    }
开发者ID:turbosheep,项目名称:ThriveVR,代码行数:7,代码来源:EventColliderScript.cs

示例14: Start

 // Use this for initialization
 void Start()
 {
     door = transform.FindChild("Inside");
     doorPanelCollider = door.FindChild("panel").GetComponent<BoxCollider>();
     doorRotation = 0;
     interactionEnabled = true;
 }
开发者ID:phillipphoenix,项目名称:LightSource,代码行数:8,代码来源:DoorController.cs

示例15: Awake

    void Awake()
    {
        gameObject.AddComponent<MogoFakeClick>().ReletedClassType = ReleadClassType.Type_InsetUI;
        m_relatedCollider = transform.GetComponentInChildren<BoxCollider>();

        m_rayHit = new RaycastHit();
    }
开发者ID:lbddk,项目名称:ahzs-client,代码行数:7,代码来源:InsetUIButton.cs


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