- 最后登录
- 2019-12-25
- 注册时间
- 2012-8-24
- 阅读权限
- 90
- 积分
- 71088
- 纳金币
- 52336
- 精华
- 343
|
网上搜集的一个摄像机脚本:刚开始直接定义几个参数 对于这几个参数比较晕 求大侠指教
// Cache缓存
private var target : Transform;
private var myTrans : Transform;
private var parentTrans : Transform;
var transitionPlane : Transform;
var occlusionDetectorPrefab : Transform;
// Attribute属性
private var distance : float = 10;
private var maxDistance : float = 15;
private var minDistance : float = 5;
//private var height : float = (distance * 2.5) - 5.5;
// Script 脚本
//X角
private var xAngle : float;
//初始X角
private var initialXAngle : float;
//上升速度
private var riseSpeed : int = 30;
//是否有碰撞
private var isColliding : boolean = false;
//目标位置
private var targetPosition : Vector3;
//对这档观看
private var toWatchForOcclusion : Array = new Array();
//遮挡探测器
private var occlusionDetector : Transform;
//走
private var go : boolean = false;
//死亡
private var dead : boolean = false;
//是否暴击
private var isCrit : boolean = false;
//暴击命中
private var critHitVec : Vector3 = Vector3.zero;
function Start()
{
//这个不懂
DontDestroyOnLoad(this);
//赋值位置??
myTrans = transform;
//赋值
parentTrans = myTrans.root;
//赋值
target = Statics.myTrans;
//
xAngle = parentTrans.localEulerAngles.x;
//初始角度==角度
initialXAngle = xAngle;
//遮挡探测器
occlusionDetector = Instantiate(occlusionDetectorPrefab, myTrans.position, myTrans.rotation);
occlusionDetector.parent = myTrans;
occlusionDetector.localScale.z = (target.position - myTrans.position).magnitude;
occlusionDetector.localPosition.z = occlusionDetector.localScale.z/2;
//Physics.IgnoreCollision(GetComponent(typeof(BoxCollider)), occlusionDetector.GetComponent(typeof(BoxCollider)));
//执行函数
BlackIn();
Execute();
}
function Execute()
{
yield; // For Statics
go = true;
}
function Update ()
{
//判断摄像机有么有碰撞:如果没有碰撞..
if (isColliding)
{
parentTrans.localEulerAngles.x = Mathf.Lerp(parentTrans.localEulerAngles.x, xAngle, .2);
}//如果有碰撞:还要判断角度是不是大于初始角度
else if (xAngle > initialXAngle)
{
xAngle -= Time.deltaTime * riseSpeed;
parentTrans.localEulerAngles.x = Mathf.Lerp(parentTrans.localEulerAngles.x, xAngle, .2);
}
//如果走=false为真:不走
if (go)
{
if (target)
{
if (PlayerControls.isMoveable){
//如果角色的控制的可以移动是真
targetPosition = target.position;
//targetPosition += Vector3(distance,height,-distance);
}
else
{
targetPosition = parentTrans.position;
}
parentTrans.position = targetPosition;//Vector3.Slerp(myTrans.position, targetPosition, Time.deltaTime);
if (isCrit)
{
myTrans.Translate(critHitVec);
}
else//走
{
// Don't look at while critting
myTrans.LookAt(parentTrans);
// Move camera to position distance distance away from parent
myTrans.position = parentTrans.position;
myTrans.Translate(0,0,-distance);
}
if (PlayerControls.isControllable)
{
if (Input.GetAxis("Zoom"))
{
if (distance <= maxDistance ;; distance >= minDistance)
{
distance -= Input.GetAxis("Zoom") * Time.deltaTime * 10;
// height -= Input.GetAxis("Zoom") * Time.deltaTime * 10 * 2.5;
}
if (distance > maxDistance || distance < minDistance){
distance += Input.GetAxis("Zoom") * Time.deltaTime * 10;
// height += Input.GetAxis("Zoom") * Time.deltaTime * 10 * 2.5;
}
// Only do while zooming
occlusionDetector.localScale.z = (target.position - myTrans.position).magnitude-1;
occlusionDetector.localPosition.z = occlusionDetector.localScale.z/2;
}
if (Input.GetAxis("Mouse Wheel"))
{
print ("Mouse wheel is being used");
distance += Input.GetAxis("Zoom") * Time.deltaTime * 10;
}
}
}
// No target
else if (dead)
{
myTrans.Translate(Time.deltaTime,0,0);
myTrans.LookAt(target);
}
else
print ("oh noes! No target...");
}
}
function StartRising()
{
isColliding = true;
if (xAngle < 89)
xAngle += Time.deltaTime * riseSpeed;
}
function StopRising()
{
isColliding = false;
}
function PlayerDied()
{
go = false;
dead = true;
for (x=0.0; x<1; x+=Time.deltaTime)
{
myTrans.LookAt(target);
myTrans.Translate(0,0, ((target.position - myTrans.position).magnitude) * Time.deltaTime);
yield;
}
}
// Goes from full black to transparent 从全黑到透明
function BlackIn()
{
var transitionTime : float = .5;
for (x=0.0; x<transitionTime; x+=Time.deltaTime)
{
transitionPlane.renderer.material.color.a = (transitionTime - x)/transitionTime;
yield;
}
transitionPlane.renderer.material.color.a = 0;
}
//从透明到全黑
function BlackOut()
{
var transitionTime : float = .5;
for (x=0.0; x<transitionTime; x+=Time.deltaTime)
{
transitionPlane.renderer.material.color.a = (x)/transitionTime;
yield;
}
}
function TransitionSlideIn()
{
transitionPlane.localPosition = Vector3(-1,0,.3);
var transitionTime : float = .5;
for (x=0.0; x<transitionTime; x+=Time.deltaTime)
{
transitionPlane.Translate(1/transitionTime*Time.deltaTime,0,0);
yield;
}
transitionPlane.localPosition = Vector3(0,0,.3);
}
function TransitionSlideOut()
{
transitionPlane.localPosition = Vector3(0,0,.3);
var transitionTime : float = .5;
for (x=0.0; x<transitionTime; x+=Time.deltaTime)
{
transitionPlane.Translate(1/transitionTime*Time.deltaTime,0,0);
yield;
}
transitionPlane.localPosition = Vector3(-1,0,.3);
}
function CriticalHit(crit : int)
{
isCrit = true;
critHitVec = Vector3.zero;
var strength : int = (crit - 30) / 5; // Assuming crit is between 30 and 80, should yield a strength between 2 and 10;
// Strength should be between 1 and 10
if (strength < 1) strength = 1;
else if (strength > 10) strength = 10;
var increase : float = strength * .02;
var max : float = .07;
for (x=0.0; x<max; x+=Time.deltaTime)
{
//critHitVec = Vector3( 0, 0, Random.Range(-1,1) ) * .3;
if (x < max/2)
{
critHitVec.z += increase;
}
else
{
critHitVec.z -= increase;
}
yield;
}
isCrit = false;
critHitVec = Vector3.zero;
} |
|