當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。