Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //SKRYPT NA OGÓLNY RUCH GŁOWICY(TURETU) CZAS I KILKA INNYCH RZECZY KTÓRE MNIE DENERWUJĄ
- #pragma strict
- //zmienne globalne
- var myProjectile : GameObject;
- var reloadTime : float = 1f;// prędkość reoladu
- var turnSpeed : float = 5f; //prędkość obracania się wieży
- var firePauseTime : float = 0;
- var muzzleEffect : GameObject;
- var errorAmount : float = .001f;
- var myTarget : Transform;
- var muzzlePosition : Transform [];//[]para elementów dobre info
- var turretBall : Transform;
- private var nextFireTime : float;//przerwa pomiędzy strzałem
- private var nextMoveTime : float;
- private var desiredRotation : Quaternion;
- private var aimError : float;
- function Start ()
- {
- }
- function Update ()
- {
- if(myTarget)
- {
- if (Time.time >= nextMoveTime)
- {
- CalculateAimPosition(myTarget.position);
- turretBall.rotation = Quaternion.Lerp(turretBall.rotation, desiredRotation, Time.deltaTime*turnSpeed);
- }
- if(Time.time >= nextFireTime)
- {
- FireProjectile();
- }
- }
- }
- function OnTriggerEnter (other : Collider)
- {
- nextFireTime = Time.time+(reloadTime*.5);//czas przeładowania to 0.5s
- myTarget = other.gameObject.transform;
- }
- function OnTriggerExit(other : Collider)
- {
- if(other.gameObject.transform == myTarget)
- {
- myTarget = null;
- }
- }
- function CalculateAimPosition(targetPos : Vector3)
- {
- var aimPoint = Vector3(targetPos.x+aimError, targetPos.y+aimError, targetPos.z+aimError);
- desiredRotation = Quaternion.LookRotation(aimPoint);
- }
- function CalculateAimError()
- {
- aimError = Random.Range(-errorAmount, errorAmount);
- }
- function FireProjectile()
- {
- //audio.Play();
- nextFireTime = Time.time+reloadTime;
- nextMoveTime = Time.time+firePauseTime;
- CalculateAimError();
- for(theMuzzlePos in muzzlePositions)
- {
- Istantiate(myProjectile, theMuzzlePos.position, theMuzzlePos.rotation);
- Istantiate(muzzleEffect, theMuzzlePos.position, theMuzzlePos.rotation);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement