查看: 4878|回复: 7

[提问] u3d13关节组件链条、固定、弹簧、角色、可配置关节

[复制链接]

2508

主题

2

听众

3万

积分

资深设计师

Rank: 7Rank: 7Rank: 7

纳金币
32806
精华
12

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

发表于 2012-12-29 10:52:42 |显示全部楼层
代码清单如下:using UnityEngine;
using System.Collections;
public class Script_06_10 : MonoBehaviour
{
//链接关节游戏对象
GameObject connectedObj = null;
//当前链接的关节组件
Component jointComponent = null;

void Start()
{   
   //获得链接关节的游戏对象
   connectedObj = GameObject.Find("Cube1");
}
void OnGUI()
{
  if(GUILayout.Button("添加链条关节"))
  {
   
   ResetJoint();
   jointComponent = gameObject.AddComponent("HingeJoint");
   HingeJoint hjoint = (HingeJoint)jointComponent;
   connectedObj.rigidbody.useGravity = ***e;
   hjoint.connectedBody = connectedObj.rigidbody;
  }
  
  if(GUILayout.Button("添加固定关节"))
  {
   ResetJoint();
   jointComponent =gameObject.AddComponent("FixedJoint");
   FixedJoint fjoint = (FixedJoint)jointComponent;
   connectedObj.rigidbody.useGravity = ***e;
   fjoint.connectedBody = connectedObj.rigidbody;
  }
  
  if(GUILayout.Button("添加弹簧关节"))
  {
   ResetJoint();
   jointComponent =gameObject.AddComponent("SpringJoint");
   SpringJoint sjoint = (SpringJoint)jointComponent;
   connectedObj.rigidbody.useGravity = ***e;
   sjoint.connectedBody = connectedObj.rigidbody;
  }
  
  if(GUILayout.Button("添加角色关节"))
  {
   ResetJoint();
   jointComponent =gameObject.AddComponent("CharacterJoint");
   CharacterJoint cjoint = (CharacterJoint)jointComponent;
   connectedObj.rigidbody.useGravity = ***e;
   cjoint.connectedBody = connectedObj.rigidbody;
  }
  
  if(GUILayout.Button("添加可配置关节"))
  {
   ResetJoint();
   jointComponent =gameObject.AddComponent("ConfigurableJoint");
   ConfigurableJoint cojoint = (ConfigurableJoint)jointComponent;
   connectedObj.rigidbody.useGravity = ***e;
   cojoint.connectedBody = connectedObj.rigidbody;
  }
}

//重置关节
void ResetJoint(){
  //销毁之前添加的关节组件
  Destroy (jointComponent);
  //重置对象位置
  this.transform.position = new Vector3(821.0f,72.0f,660.0f);
  connectedObj.gameObject.transform.position = new Vector3(805.0f,48.0f,660.0f);
  //不感应重力
  connectedObj.rigidbody.useGravity = false;
}
}
回复

使用道具 举报

2508

主题

2

听众

3万

积分

资深设计师

Rank: 7Rank: 7Rank: 7

纳金币
32806
精华
12

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

发表于 2012-12-29 10:54:47 |显示全部楼层
如果觉得好的话就赞一个吧~
回复

使用道具 举报

2722

主题

42

听众

3万

积分

资深设计师

Rank: 7Rank: 7Rank: 7

纳金币
38266
精华
111

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

发表于 2012-12-31 02:43:06 |显示全部楼层
谢谢楼主的帖子分享,学习了
回复

使用道具 举报

40

主题

0

听众

2万

积分

资深设计师

Rank: 7Rank: 7Rank: 7

纳金币
279
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

发表于 2013-8-14 10:06:31 |显示全部楼层
谢谢楼主分享
回复

使用道具 举报

40

主题

0

听众

2万

积分

资深设计师

Rank: 7Rank: 7Rank: 7

纳金币
279
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

发表于 2013-8-14 10:06:56 |显示全部楼层
有没有模拟真是世界的弹簧效果?
回复

使用道具 举报

12

主题

0

听众

3738

积分

中级设计师

Rank: 5Rank: 5

纳金币
3
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

发表于 2013-8-16 10:38:33 |显示全部楼层
感谢分享
回复

使用道具 举报

1

主题

6

听众

8524

积分

高级设计师

Rank: 6Rank: 6

纳金币
2
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

发表于 2017-8-30 15:02:56 |显示全部楼层
好资源哦,顶一下
回复

使用道具 举报

0

主题

5

听众

1748

积分

助理设计师

Rank: 4

纳金币
272
精华
0

周年庆

发表于 2017-8-30 16:38:21 |显示全部楼层
赞一个 哈哈哈哈
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-3-28 22:17 , Processed in 0.163898 second(s), 33 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部