• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# BoxCollider类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: closestPointOnOBB

    static Vector3 closestPointOnOBB(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.worldToLocalMatrix.MultiplyPoint3x4(to);

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

        // Inverse scale it by the colliders scale
        var localNorm =
            new Vector3(
                Mathf.Clamp(local.x, -collider.extents.x, collider.extents.x),
                Mathf.Clamp(local.y, -collider.extents.y, collider.extents.y),
                Mathf.Clamp(local.z, -collider.extents.z, collider.extents.z)
            );

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

        // Return resulting point
        return ct.localToWorldMatrix.MultiplyPoint3x4(localNorm);
    }
开发者ID:Ramzawulf,项目名称:unityassets,代码行数:25,代码来源:RPGCollisions.cs


示例17: OnStateExit

    // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    //override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
    //
    //}
    // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
    //override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
    //
    //}
    // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
    public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        myBoxCollider = animator.GetComponent<PlayerController>().mySwordBoxCollider;
        myBoxCollider.enabled = false;

        animator.SetBool("Whirlwinding", false);
    }
开发者ID:Unityprojektgruppe2,项目名称:Unity-Project---Group-2-NEW,代码行数:16,代码来源:WhirlwindStopAnimationBehaviour.cs


示例18: Awake

	public void Awake() {
		_characterCollider = GetComponent<BoxCollider>();
		_characterRigidbody = GetComponent<Rigidbody>();
        _slothSnapper = GetComponent<Snapper>();
		_slothController = GetComponent<SlothController>();
		ragdolled = false;
	}
开发者ID:ferdbold,项目名称:littleawfuljam2016,代码行数:7,代码来源:RagdollToggle.cs


示例19: Start

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


示例20: Awake

	private void Awake ()
	{
		if (transform.parent == null)
		{
			Debug.LogError("BoxColliderGenerator ERROR: this GO is not parented");
		}
		else
		{
			MeshCollider meshCollider = GetComponentInParent<MeshCollider>();
			boxCollider = GetComponent<BoxCollider>();

			if (meshCollider == null || boxCollider == null)
			{
				Debug.Log("BoxColliderGenerator ERROR: mesh or box collider not defined");
			}
			else
			{
				
			}
	//		meshCollider = GetComponent<MeshCollider>();
	//		logCollider = gameObject.AddComponent<BoxCollider>();
	//		logCollider.isTrigger = true;
			//insideOffsetMultiplier = -insideOffsetMultiplier;
			size = meshCollider.bounds.size;
			boxCollider.size = new Vector3(size.x * insideOffsetMultiplier.x, size.y * insideOffsetMultiplier.y, size.z * insideOffsetMultiplier.z);

			transform.localPosition = Vector3.zero;
			transform.eulerAngles = rotationOffset;
		}
	}
开发者ID:pencilking2002,项目名称:TOF_Movement_Protype,代码行数:30,代码来源:BoxColliderGenerator.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# BoxModuleI类代码示例发布时间:2022-05-24
下一篇:
C# Box类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap