// Use this for initialization protected virtual void Start() { //Get a component reference to the Character's animator component animator = GetComponent <Animator>(); render = GetComponent <SpriteRenderer>(); //Get the rigid body on the prefab charBody = GetComponent <Rigidbody2D>(); //Set our default values //maxHealth = 25; Max Health set by inspector moveDec = 1; lastDir = -1; //Set our health curHealth = maxHealth; canRegen = true; //Default looking idle animator.SetInteger("Direction", 0); //Get our gammaneger gameManager = GameObject.Find("GameManager").GetComponent <GameManager>(); //Get our camera script actionCamera = Camera.main.GetComponent <ActionCamera>(); hurt = GameObject.Find("Hurt").GetComponent <AudioSource> (); }
// Use this for initialization void Start () { //Get a component reference to the Character's animator component animator = GetComponent<Animator>(); render = GetComponent<SpriteRenderer>(); //Get the rigid body on the prefab bullBody = GetComponent<Rigidbody2D>(); //Set our bullet strength and speed strength = 4; speed = 40; //Go after our player! player = GameObject.Find("Player").GetComponent<Player>(); //Get our Player current Direction if (player.getDirection () > 0 || (player.getDirection() == 0 && player.getLastDirection() > 0 )) { animator.SetInteger ("Direction", 1); playerRight = true; } else { playerRight = false; animator.SetInteger ("Direction", -1); } //Play our shooting sound shoot = GameObject.Find ("Shoot").GetComponent<AudioSource> (); shoot.Play (); //Get our camera script actionCamera = Camera.main.GetComponent<ActionCamera>(); }
// Use this for initialization protected virtual void Start() { //Get a component reference to the Character's animator component animator = GetComponent <Animator>(); render = GetComponent <SpriteRenderer>(); //Get the rigid body/collider on the prefab charBody = GetComponent <Rigidbody2D>(); charCollider = GetComponent <Collider2D>(); //Set our default values moveDec = 1; //Set our health curHealth = maxHealth; canRegen = true; //Default looking idle/right direction = 1; //Get our gamemaneger gameManager = GameObject.Find("Game Manager").GetComponent <StateManager>(); //Get our camera script actionCamera = Camera.main.GetComponent <ActionCamera>(); }
private void Awake() { if (instance != null) { Debug.LogError("Camera singleton has already assigned instance"); } instance = this; }
void Awake() { _uniqueInstance = this; _ltPositions = new List <Vector3>(); _posPlayer = GameObject.FindWithTag("Player").transform; _curCameraAction = eStateCamera.FOLLOW; }
protected override void OnValidate() { base.OnValidate(); ActionCamera script = target as ActionCamera; if (script == null) { return; } string name = script.cam.gameObject.name; script.name += name; }
public void Update() { float lookX = FixValue(Input.GetAxis("4th")); float lookY = FixValue(Input.GetAxis("5th")) * (ActionCamera.invertCameraY ? -1 : 1); //Debug.Log(lookX); //Debug.Log(lookY); ActionCamera.orbitX += lookX * HorizontalCameraSpeed * Time.deltaTime; ActionCamera.orbitY += lookY * VerticalCameraSpeed * Time.deltaTime; ActionCamera.orbitY = ClampAngle(ActionCamera.orbitY); Quaternion rotation = Quaternion.Euler(ActionCamera.orbitY, ActionCamera.orbitX, 0); Transform.rotation = rotation; Vector3 position = rotation * new Vector3(0, ActionCamera.actionHeight, ActionDistance) + Target.position; if (Repositioning.active) { RaycastHit hit; if (Physics.Linecast(Target.position, position, out hit, ~(LayerMask.GetMask(Repositioning.ignoredLayers)))) { newDistance = -hit.distance; Camera.main.nearClipPlane = Repositioning.onRepositionNearClipPlane; } else { newDistance = Mathf.Lerp(newDistance, ActionDistance, ActionLerpSpeed * Time.deltaTime); Camera.main.nearClipPlane = Repositioning.onNormalNearClipPlane; } } Transform.position = Vector3.Lerp(Transform.position, rotation * new Vector3(0, ActionHeight, newDistance) + Target.position, Time.deltaTime * 19f); if (!ActionCamera.ManageInputFromOtherScript) { //must be removed, use ActionCamera methods for switching states. if (Input.GetKeyDown(KeyCode.M)) { ActionCamera.Lock(); } } }
protected virtual void OnSceneGUI() { ActionCamera boundsExample = (ActionCamera)target; // copy the target object's data to the handle m_BoundsHandle.center = boundsExample.cameraBounds.center; m_BoundsHandle.size = boundsExample.cameraBounds.size; // draw the handle EditorGUI.BeginChangeCheck(); m_BoundsHandle.DrawHandle(); if (EditorGUI.EndChangeCheck()) { // record the target object before setting new values so changes can be undone/redone Undo.RecordObject(boundsExample, "Change Bounds"); // copy the handle's updated data back to the target object Bounds newBounds = new Bounds(); newBounds.center = m_BoundsHandle.center; newBounds.size = m_BoundsHandle.size; boundsExample.cameraBounds = newBounds; } }
// Use this for initialization void Start() { //Get a component reference to the Character's animator component animator = GetComponent <Animator>(); render = GetComponent <SpriteRenderer>(); //Get the rigid body on the prefab bullBody = GetComponent <Rigidbody2D>(); //Set our bullet strength and speed strength = 4; speed = 40; //Go after our player! player = GameObject.Find("Player").GetComponent <Player>(); //Get our Player current Direction if (player.getDirection() > 0 || (player.getDirection() == 0 && player.getLastDirection() > 0)) { animator.SetInteger("Direction", 1); playerRight = true; } else { playerRight = false; animator.SetInteger("Direction", -1); } //Play our shooting sound shoot = GameObject.Find("Shoot").GetComponent <AudioSource> (); shoot.Play(); //Get our camera script actionCamera = Camera.main.GetComponent <ActionCamera>(); }
void Awake() { singleton = this; }
public CameraActionState(ActionCamera camera) { this.ActionCamera = camera; }
public CameraLockState(ActionCamera camera) { ActionCamera = camera; }
public void Update() { //if is too far away return in default state if (Vector3.Distance(focusedTarget.Transform.position, Transform.position) > LockMaxDistanceFromTarget) { focusedTarget.OnTargetLosed(); ActionCamera.Unlock(); return; } Vector3 newFor = (focusedTarget.Transform.position - Transform.position).normalized; Transform.rotation = Quaternion.LookRotation(Vector3.Lerp(Transform.forward, newFor, Time.deltaTime * 8f)); Vector3 position = Transform.rotation * new Vector3(0, LockHeight, LockDistance) + Target.position; if (Repositioning.active) { RaycastHit hit; if (Physics.Linecast(Target.position, position, out hit, ~(LayerMask.GetMask(Repositioning.ignoredLayers)))) { newDistance = -hit.distance; Camera.main.nearClipPlane = Repositioning.onRepositionNearClipPlane; } else { newDistance = Mathf.Lerp(newDistance, LockDistance, LockLerpSpeed * Time.deltaTime); Camera.main.nearClipPlane = Repositioning.onNormalNearClipPlane; } } position = Transform.rotation * new Vector3(0, LockHeight, newDistance) + Target.position; position.y = LockHeight; Transform.position = Vector3.Lerp(Transform.position, position, Time.deltaTime * 10f); if (!ActionCamera.ManageInputFromOtherScript) { //must be removed, use ActionCamera methods for switching states. if (Input.GetKeyDown(KeyCode.JoystickButton0)) { focusedTarget.OnTargetReleased(); ActionCamera.Unlock(); } } if (Input.GetKeyDown(KeyCode.Z)) { ITargettable t = ActionCamera.GetTargetFromSide(-30); if (t != null) { focusedTarget = t; } } else if (Input.GetKeyDown(KeyCode.X)) { ITargettable t = ActionCamera.GetTargetFromSide(30); if (t != null) { focusedTarget = t; } } }
public static void AnimateMovement(PieceBehaviour movingPiece) { GameKeeper gameKeeper = GameObject.Find(Constants.PieceNames.ChessBoard).GetComponent <GameKeeper>(); float finalXPosition = gameKeeper.GetTransformFromPosition(movingPiece.getPiece().GetCurrentPosition()).x + HardcodedOffset(movingPiece).x; float finalYPosition = float.Parse(movingPiece.gameObject.GetComponent <MeshRenderer>().bounds.extents.y.ToString("0.00")) + HardcodedOffset(movingPiece).y; float finalZPosition = gameKeeper.GetTransformFromPosition(movingPiece.getPiece().GetCurrentPosition()).z + HardcodedOffset(movingPiece).z; float lerpSpeed; if (gameKeeper.hasGameStarted()) { if (GameObject.Find(Constants.ActionCameraObject).GetComponent <ActionCamera>().isActionCameraEnabled()) { // Nice and slow lerpSpeed = 0.02f; } else { // No one's gonna wait that long lerpSpeed = 0.04f; } } else { lerpSpeed = 0.025f; } Vector3 currentLocation = movingPiece.gameObject.GetComponent <Transform>().position; Vector3 newLocation; bool stillInMotion = false; if (isSpaceship(movingPiece.getPiece())) { // Fly in, and then land if (Mathf.Abs(currentLocation.x - finalXPosition) >= 0.01f || Mathf.Abs(currentLocation.z - finalZPosition) >= 0.01f) { newLocation = new Vector3(Mathf.Lerp(currentLocation.x, finalXPosition, lerpSpeed), Mathf.Lerp(currentLocation.y, finalYPosition + 2, lerpSpeed), Mathf.Lerp(currentLocation.z, finalZPosition, lerpSpeed)); movingPiece.gameObject.GetComponent <Transform>().position = newLocation; stillInMotion = true; } else if (Mathf.Abs(currentLocation.y - finalYPosition) >= 0.01f) { newLocation = new Vector3(currentLocation.x, Mathf.Lerp(currentLocation.y, finalYPosition, lerpSpeed), currentLocation.z); movingPiece.gameObject.GetComponent <Transform>().position = newLocation; stillInMotion = true; } } else { // Fade in like an adept Force user (or rather, Z warrior) Material meshMaterial = movingPiece.gameObject.GetComponent <MeshRenderer>().material; float currentAlpha = meshMaterial.GetColor("_Color").a, targetAlpha = 1.0f; meshMaterial.SetColor("_Color", new Color(meshMaterial.GetColor("_Color").r, meshMaterial.GetColor("_Color").g, meshMaterial.GetColor("_Color").b, Mathf.Lerp(currentAlpha, targetAlpha, lerpSpeed))); // Slide super gracefully if (Mathf.Abs(currentLocation.x - finalXPosition) >= 0.01f || Mathf.Abs(currentLocation.z - finalZPosition) >= 0.01f) { newLocation = new Vector3(Mathf.Lerp(currentLocation.x, finalXPosition, lerpSpeed), currentLocation.y, Mathf.Lerp(currentLocation.z, finalZPosition, lerpSpeed)); movingPiece.gameObject.GetComponent <Transform>().position = newLocation; stillInMotion = true; } else if (Mathf.Abs(currentAlpha - targetAlpha) >= 0.01f) { stillInMotion = true; } else if (Mathf.Abs(currentAlpha - targetAlpha) < 0.01f) { // This case is required to make the pieces opaque if (movingPiece.getPiece().side == Side.Black) { movingPiece.gameObject.GetComponent <MeshRenderer>().material = opaqueBlackMaterial; } else { movingPiece.gameObject.GetComponent <MeshRenderer>().material = opaqueWhiteMaterial; } } } if (!stillInMotion) { // Ready to roll movingPiece.gameObject.GetComponent <PieceBehaviour>().isInAnimationState = false; TriggerNextStartAnimation(movingPiece.getPiece()); if (gameKeeper.hasGameStarted()) { ActionCamera actionCamera = GameObject.Find(Constants.ActionCameraObject).GetComponent <ActionCamera>(); if (actionCamera.isActionCameraEnabled()) { actionCamera.EnableMainCamera(); } if (GameObject.Find(Constants.PieceNames.ChessBoard).GetComponent <GameKeeper>().chessBoard.CurrentMovingSide() == movingPiece.getPiece().side) { EventManager.TriggerEvent(Constants.EventNames.NewPlayerTurn); } } else { EventManager.TriggerEvent(Constants.EventNames.PieceSpawned); } } }