当前位置: 编程技术>移动开发
本页文章导读:
▪Unity3D 兑现爆炸效果的函数 Unity3D 实现爆炸效果的函数var trigObj : Transform = null;
var explosion : Transform = null;
var tnt : Transform = null;
private var collidedObj : Collider[];
function Boom () {
collidedObj = Physics.OverlapSphere(tnt.transform.position, 1);.........
▪ Unity3D 摄影机转换及随鼠标转动 Unity3D 摄像机转换及随鼠标转动嘿嘿,这个我还不太熟悉,只是大概懂。以后自己写个更好的和大家分享哈。
#pragma strict
public var charObj : Transform;
public var camNum : int = 0;
public var camDistance : floa.........
▪ Unity3D 简略的动画 Unity3D 简单的动画这个挺繁杂,嘿嘿,主要是为自己记录下啦。大家只需要注意下crossFade和animation的相关函数就可以了。
#pragma strict
private var Controller : CH_Character;
private var Controller_other : CH_Con.........
[1]Unity3D 兑现爆炸效果的函数
来源: 互联网 发布时间: 2014-02-18
Unity3D 实现爆炸效果的函数
var trigObj : Transform = null; var explosion : Transform = null; var tnt : Transform = null; private var collidedObj : Collider[]; function Boom () { collidedObj = Physics.OverlapSphere(tnt.transform.position, 1); // Physics.OverlapSphere函数能返回一组对象的集合。而这组对象便是圆内包含的对象。 // 这个圆的中心点是函数的第一个参数,第二个参数是半径大小。 for (var obj in collidedObj) { Instantiate(explosion, obj.transform.position, transform.rotation); // 引用Unity3D Extention的Detonator包里的Detonator-Tiny对象,这一行能 // 实现爆炸火花的效果。 Destroy(obj.gameObject); } } function Start () { } function Update () { if (tnt != null) { if (trigObj.GetComponent("Button").ReturnButtonStatus()) { Boom(); } } }
[2] Unity3D 摄影机转换及随鼠标转动
来源: 互联网 发布时间: 2014-02-18
Unity3D 摄像机转换及随鼠标转动
嘿嘿,这个我还不太熟悉,只是大概懂。以后自己写个更好的和大家分享哈。
#pragma strict public var charObj : Transform; public var camNum : int = 0; public var camDistance : float[]; public var heightOffset : float[]; public var yAngleLimit : float[]; public var mouseSpeed : float[]; public var camDist : float; public var hOffset : float; private var startRotation : float; private var x = 0.0; private var y = 0.0; enum CamType {FP, SP, TP} private var cameraType : CamType; function SetCamValues() { camNum = ChangeCamValues(); switch(cameraType) { case CamType.FP: camDist = camDistance[0]; hOffset = heightOffset[0]; break; case CamType.SP: camDist = camDistance[1]; hOffset = heightOffset[1]; break; case CamType.TP: camDist = camDistance[2]; hOffset = heightOffset[2]; break; } } function Apply() { x -= Input.GetAxis("Mouse X") * mouseSpeed[0] * Time.deltaTime; y += Input.GetAxis("Mouse Y") * mouseSpeed[1] * Time.deltaTime; y = ClampAngle(y, yAngleLimit[0], yAngleLimit[1]); var rotation = Quaternion.Euler(y, x + startRotation, 0); var targPos = rotation * Vector3(0.0, 0.0, camDist) + charObj.position; targPos.y += hOffset; transform.rotation = rotation; transform.position = targPos; } function ClampAngle(angle : float, min : float, max : float) { if (angle < -360) angle += 360; if (angle > 360); angle -= 360; return Mathf.Clamp (angle, min, max); } function Initialize(Player : Transform) { } function ChangeCamValues() : int{ if (camNum == 1){ cameraType = CamType.SP; camNum = 2; return camNum; // why return rather than assign directly. } if (camNum == 2){ cameraType = CamType.TP; camNum = 3; return camNum; } if (camNum == 3){ cameraType = CamType.FP; camNum = 1; return camNum; } } function Start () { camNum = 1; cameraType = CamType.FP; startRotation = charObj.transform.eulerAngles.y; y = transform.eulerAngles.y; x = transform.eulerAngles.x; SetCamValues(); } function Update () { } function LateUpdate () { Apply(); }
这组数据比较重要哦~~~~
[3] Unity3D 简略的动画
来源: 互联网 发布时间: 2014-02-18
Unity3D 简单的动画
这个挺繁杂,嘿嘿,主要是为自己记录下啦。大家只需要注意下crossFade和animation的相关函数就可以了。
#pragma strict private var Controller : CH_Character; private var Controller_other : CH_Controller; public var forwardSpeed : float = 5.0; public var backwardSpeed : float = 3.0; public var strafingSpeed : float = 4.0; public var runningSpeed : float = 10.0; public var idleAnimationSpeed : float = 1.0; public var forwardAnimationSpeed : float = 6.0; public var runningAnimationSpeed : float = 3.0; public var backwardAnimationSpeed : float = 1.0; public var strafingAnimationSpeed : float = 3.0; public var jumpingAnimationSpeed : float = 1.5; public var ShootingAnimationSpeed : float = 1.0; function Start () { animation.AddClip(animation["shoot"].clip, "shootUpperBody"); animation.AddClip(animation["shoot2"].clip, "shootUpperBody2"); animation["shootUpperBody"].AddMixingTransform(transform.Find("COG/Spine")); animation["shootUpperBody2"].AddMixingTransform(transform.Find("COG/Spine")); animation["idle"].layer = -1; animation["run"].layer = -1; animation["jump"].layer = -1; animation["walk_forward"].layer = -1; animation["walk_backward"].layer = -1; animation["walk_side"].layer = -1; animation.wrapMode = WrapMode.Loop; animation["jump"].wrapMode = WrapMode.ClampForever; animation["shoot"].wrapMode = WrapMode.Once; animation["shoot2"].wrapMode = WrapMode.Once; animation["shootUpperBody"].wrapMode = WrapMode.Once; animation["shootUpperBody2"].wrapMode = WrapMode.Once; animation["idle"].speed = idleAnimationSpeed; animation["walk_forward"].speed = forwardAnimationSpeed; animation["run"].speed = runningAnimationSpeed; animation["walk_backward"].speed = backwardAnimationSpeed; animation["walk_side"].speed = strafingAnimationSpeed; animation["jump"].speed = jumpingAnimationSpeed; animation["shootUpperBody"].speed = ShootingAnimationSpeed; animation["shootUpperBody2"].speed = ShootingAnimationSpeed; animation.Stop(); animation.Play("idle"); } function DetermineDirection () { if (Controller_other.bIsShooting) { if (!animation.IsPlaying("shootUpperBody")) animation.Play("shootUpperBody"); } if (Controller_other.bIsShootingAlt) { if (!animation.IsPlaying("shootUpperBody2")) animation.Play("shootUpperBody2"); } if (Controller.inAir) { if (!Controller.jumpClimax) { animation.CrossFade("jump", 0.5, PlayMode.StopSameLayer); } else { animation.Rewind("jump"); } } else if (Controller.MoveDirection == Vector3.zero) { animation.CrossFade("idle"); } else if (Controller.MoveDirection.z > 0) { if (Controller.isRunning) { Controller.Speed = runningSpeed; animation.CrossFade("run", 0.5, PlayMode.StopSameLayer); } else { Controller.Speed = forwardSpeed; animation.CrossFade("walk_forward", 0.5, PlayMode.StopSameLayer); } } else if (Controller.MoveDirection.z < 0) { Controller.Speed = backwardSpeed; animation.CrossFade("walk_backward", 0.5, PlayMode.StopSameLayer); } else if (Controller.MoveDirection.x > 0 || Controller.MoveDirection.x < 0) { Controller.Speed = strafingSpeed; animation.CrossFade("walk_side", 0.5, PlayMode.StopSameLayer); } } function Awake () { Controller = this.gameObject.GetComponent(CH_Character); Controller_other = this.gameObject.GetComponent(CH_Controller); } function Update () { DetermineDirection(); }
最新技术文章: