unity3d 显示图片预制物图片一样

鲜花11006朵
阅读:1548回复:5
实例化预制的时候怎么把预制物体和某一物体的旋转一样呢
发布于: 12:56
726 || this.offsetHeight>700){if(this.offsetWidth/726 > this.offsetHeight/700){this.width=726;}else{this.height=700;}}" style="max-width:726max-height:700" title="点击查看原图" onclick="if(this.parentNode.tagName!='A') window.open('/forum/attachment/Mon__54bab4.png');" />就是红色的片的旋转和那个球的旋转同步&
好好学习,天天向上。
发布于: 13:22
你实例化的时候不是应该有一个参数是角度的吗?
鲜花11006朵
发布于: 13:41
:你实例化的时候不是应该有一个参数是角度的吗? ( 13:22) 是啊,但是这个角度是变动的,用Euler后,有偏差,效果不好
好好学习,天天向上。
鲜花11006朵
发布于: 13:54
Instantiate(Plane,point,this.transform.rotation);搞定了,被我想复杂了。
好好学习,天天向上。
鲜花1433朵
发布于: 14:42
大多数时候 &我们只是复制父物体下的一个子物体,所以必须GameObject o = Instantiate( &SubObject) &as &GameO然后o.transform.parent = SubObject.transform.parento.transform.localposition = SubObject.transform.localposition o.transform.localscale = SubObject.transform.localscale 因为Instantiate创建的物体会先落到根目录上
cocos2dx 转职成unity3d的苦手
发布于: 09:44
您需要登录后才可以回帖,&或者&
Powered byUnity3D基础教程4-1:在运行时初始化预制品
这是一个工作流模式,在Unity里可反复使用。在一开始,你可能惊讶,为什么会是这样好,因为该脚本创建立方体的代码只有2行长。
But because you are using a Prefab now, you can adjust the Prefab in seconds. Want to change the mass of all those instances? Adjust the Rigidbody in the Prefab only once. Want to use a different Material for all the instances? Drag the Material onto the Prefab only once. Want to change friction? Use a different Physic Material in the Prefab's collider. Want to add a Particle System to all those boxes? Add a child to the Prefab only once.
但是,因为现在你使用的是预制品,你可以在几秒钟内调整预制品。想要改变的那些例子吗?在预制品里调整刚体仅一次。想要使用一种不同的材料对所有的例子吗?拖拽物质到预制品上仅一次。想要改变摩擦吗?使用不同的物理资料在预制品的碰撞器里。要添加一个粒子系统给所有那些方框吗?添加一个子预制品仅一次。
Instantiating rockets & explosions火箭和爆炸的初始化
Here's how Prefabs fit into this scenario: 现在是预制品如何融入到这个场景里:
A rocket launcher instantiates a rocket Prefab when the user presses fire. The Prefab contains a mesh, Rigidbody, Collider, and a child GameObject that contains a trail particle system.
一个火箭发射实例化一个火箭预制品当用户按发射键时。预制品包含一个网格、刚体、碰撞器以及一个含有痕迹粒子系统的子GameObject。
The rocket impacts and instantiates an explosion Prefab. The explosion Prefab contains a Particle System, a light that fades out over time, and a script that applies damage to surrounding GameObjects.
火箭影响和一个爆炸预制品的实例。爆炸预制包含一个粒子系统、随着时间的推移淡出光以及脚本应用损害周围的GameObjects。
While it would be possible to build a rocket GameObject completely from code, adding Components manually and setting properties, it is far easier to instantiate a Prefab. You can instantiate the rocket in just one line of code, no matter how complex the rocket's Prefab is. After instantiating the Prefab you can also modify any properties of the instantiated object (e.g. you can set the velocity of the rocket's Rigidbody).
虽然有可能从代码完成构建一个火箭的GameObject,完全手动添加组件并设置属性,容易得多去实例化一个预制品。你可以在仅有一行代码里实例化火箭,无论多么复杂,火箭是预制的。实例化预制品后,你还可以修改实例化对象的任何属性(例如,可以设置的火箭刚体速度)。
Aside from being easier to use, you can update the prefab later on. So if you are building a rocket, you don't immediately have to add a Particle trail to it. You can do that later. As soon as you add the trail as a child GameObject to the Prefab, all your instantiated rockets will have particle trails. And lastly, you can quickly tweak the properties of the rocket Prefab in the Inspector, making it far easier to fine-tune your game.
除了更容易的使用,稍后你可以更新预制。因此,如果你要构建一个火箭,你不立即需要添加一个粒子痕迹给它。以后你能做到这一点。只要你添加一个子GameObject到预制品,所有实例化的火箭将有粒子痕迹。最后,你可以快速调整火箭的性能预制在检视器里,使微调你的游戏容易得多。
This script shows how to launch a rocket using the Instantiate() function.
此脚本显示了如何使用发射火箭的Instantiate()函数。
// Require the rocket to be a rigidbody.
// This way we the user can not assign a prefab without rigidbody
var rocket : R
var speed = 10.0;
function FireRocket () {
var rocketClone : Rigidbody = Instantiate(rocket, transform.position, transform.rotation);
rocketClone.velocity = transform.forward *
// You can also acccess other components / scripts of the clone
rocketClone.GetComponent(MyRocketScript).DoSomething();
// Calls the fire method when holding down ctrl or mouse
function Update () {
if (Input.GetButtonDown(&Fire1&)) {
FireRocket();
Replacing a character with a ragdoll or wreck 取代一个拥有破碎的或损坏的飞船
Let's say you have a fully rigged enemy character and he dies. You could simply play a death animation on the character and disable all scripts that usually handle the enemy logic. You probably have to take care of removing several scripts, adding some custom logic to make sure that no one will continue attacking the dead enemy anymore, and other cleanup tasks.
假设你有一个完全操纵敌人的角色和它死亡。你可以简单地处理一个死亡的动画和禁用所有通常敌人的逻辑处理脚本。你可能要消除几个脚本,加入一些自定义的逻辑,以确保没有人会继续攻击死亡的敌人,以及其它清理工作。
A far better approach is to immediately delete the entire character and replace it with an instantiated wrecked prefab. This gives you a lot of flexibility. You could use a different material for the dead character, attach completely different scripts, spawn a Prefab containing the object broken into many pieces to simulate a shattered enemy, or simply instantiate a Prefab containing a version of the character.
欢迎与本站!
QQ交流群1:
QQ交流群2:[Unity3D]人物模型的换装 - 下载频道
- CSDN.NET
&&&&[Unity3D]人物模型的换装
[Unity3D]人物模型的换装
人物的换装是游戏开发的一个基本的技术,初来公司,老板就要我学习一下人物换装,也当是给我练练手吧,然后我接到一个需求之后,就要开始学习和搜集资料来实现这一功能,一下是学习心得,接下来我们就一起来学习一下,仅仅供新手参考。
首先 我们将从美工那儿获取到的人物模型资源加载到本地,然后通过写代码挂载到人物模型上面。以下是挂在在模型上面的js代码,也就是换装的脚本:
[javascript] view plaincopyprint?在CODE上查看代码片派生到我的代码片
var ME1 : M
var MA1 : M
private var TK = 0;
var ME2 : M
var MA2 : M
private var WQ = 0;
var ME3 : M
var MA3 : M
private var ZJ = 0;
var ME4 : M
var MA4 : M
private var YJ = 0;
function OnGUI()
GUILayout.Label(&&);
if(GUILayout.Button (&Helm头盔&))
if(TK == 1)
transform.Find(&group2&).Find(&Object02&).GetComponent(MeshFilter).mesh =
transform.Find(&group2&).Find(&Object02&).renderer.material =
transform.Find(&group2&).Find(&Object02&).GetComponent(MeshFilter).mesh = ME1;
transform.Find(&group2&).Find(&Object02&).renderer.material = MA1;
if(GUILayout.Button (&Weapon武器&))
if(WQ == 1)
若举报审核通过,可奖励20下载分
被举报人:
举报的资源分:
请选择类型
资源无法下载
资源无法使用
标题与实际内容不符
含有危害国家安全内容
含有反动色情等内容
含广告内容
版权问题,侵犯个人或公司的版权
*详细原因:
您可能还需要
移动开发下载排行unity3d人物控制脚本的实现(转:到达梦想博客)
// Require a character controller to be attached to the same game object
@script RequireComponent(CharacterController)
var _speed :
var _jumpspeed :
var _rotatespeed :
var _originalgravity :
var _gravity :
var _addgravity :
var _moveDirection: Vector3;
var _lastDirection: Vector3;
var _originalRotation : Q
var _run : AnimationC
var _idle : AnimationC
var _attack : AnimationC
var _jump : AnimationC
private var _controller : CharacterC
enum PlayerState
STATE_READY
STATE_IDLE
STATE_ATTACK
STATE_JUMP
private var _playerstate : PlayerS
function Start(){
_speed = 50F;
_jumpspeed = 40F;
_rotatespeed = 10F;
_originalgravity = 40;
_gravity = 40;
_addgravity = 3;
_canjump =
_moveDirection = Vector3.
_lastDirection = Vector3.
_originalRotation = new Quaternion(0f, 0f, 0f, 1f);
_grounded =
_animation = GetComponent(Animation);
_controller = GetComponent(CharacterController);
_playerstate = PlayerState.STATE_READY;
_moveDirection.y = -1; //给Y轴方向一个初始值,以使其可以与地面正确相撞
function Update () {
//模型的旋转(临时)
if(Input.GetKey("a")){
transform.Rotate(-Vector3.up*2);
if(Input.GetKey("d")){
transform.Rotate(Vector3.up*2);
if(_grounded)
//本地空间水平移动方向向量
_moveDirection = Vector3( 0 , -1 ,Input.GetAxis("Vertical"));
//本地空间移动方向转为世界空间的移动方向向量
_moveDirection = transform.TransformDirection(_moveDirection);
_moveDirection *= _
//重力速度还原
_gravity = _
if (Input.GetButton("Jump") )
_playerstate = PlayerState.STATE_JUMP;
//获得初速度
_moveDirection.y = _
_animation.Play("jump");
//如果当前处于跳跃中,就算一下Y向量
if(_playerstate == PlayerState.STATE_JUMP)
_gravity += _
_moveDirection.y -= _gravity * Time.deltaT
//移动,并获得碰撞标示
var _flags : CollisionFlags =_controller.Move(_moveDirection *Time.deltaTime);
//是否已经着地
_grounded = (_flags & CollisionFlags.CollidedBelow) != 0;
print(_grounded);
//=======================================================================
if(Input.GetKeyUp("f") && _grounded &&_playerstate == PlayerState.STATE_IDLE)
_playerstate = PlayerState.STATE_ATTACK;
_animation.Play("attack");
if(_moveDirection.x == 0
_moveDirection.z == 0&& _grounded && _playerstate != PlayerState.STATE_ATTACK)
if(_moveDirection != Vector3(0,0,0))
if(_playerstate != PlayerState.STATE_ATTACK)
_playerstate = PlayerState.STATE_IDLE;
_animation.Play("idle");
if((_moveDirection.x != 0 || _moveDirection.z != 0) &&_grounded
_playerstate = PlayerState.STATE_RUN;
_animation.Play("run");
//供外部UI调用的接口,调用攻击动作
function PlayAnimation_Attack()
if(_grounded && (_playerstate ==PlayerState.STATE_IDLE||_playerstate ==PlayerState.STATE_ATTACK))
_playerstate = PlayerState.STATE_ATTACK;
_animation.Play("attack");
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

我要回帖

更多关于 unity3d 显示图片 的文章

 

随机推荐