当前位置:  编程技术>移动开发
本页文章导读:
    ▪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();
}



    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
.net/c#/asp.net iis7站长之家
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3