// Use this for initialization void Start() { origScale = transform.localScale; origPosition = transform.position; CapsuleCollider cc = GetComponent <CapsuleCollider>(); markerHeight = cc.height * 0.5f + cc.radius; //inject process hit method LookAtObject lao = GetComponent <LookAtObject>(); lao._processObjectMethodToCall = ProcessObject; InitMarker(); // Occlusion collision if (occlusionCollisionPrefab != null) { occlusionCollision = Instantiate(occlusionCollisionPrefab, transform.position, Quaternion.identity); origScaleOcclusionCollision = occlusionCollision.transform.localScale; } else { occlusionCollision = null; } markers.Add(this); }
// Use this for initialization public void Start() { playerMoveComp = GetComponent <Movement>(); playerHealthComp = GetComponent <PlayerHealth>(); playerThrowComp = GetComponent <PlayerThrowing>(); otherPlayer = playerMoveComp.otherPlayer.gameObject; otherPlayerAnimatorManager = otherPlayer.GetComponent <PlayerPieceAnimatorManager>(); for (int i = 0; i < playerMoveComp.pieces.Count; i++) { Animator pieceAnimator = playerMoveComp.pieces[i].gameObject.GetComponent <Animator>(); if (pieceAnimator) { playerPieceAnimators.Add(pieceAnimator); playerPieceDictionary.Add(pieceAnimator, playerMoveComp.pieces[i]); //add the pieces and their animators to a dictionary for ease of use playerFaceDictionary.Add(pieceAnimator, pieceAnimator.transform.GetComponentInChildren <Animator>()); //add face animators LookAtObject tempLookComp = pieceAnimator.gameObject.GetComponentInChildren <LookAtObject>(); //get the look at object component on the face and set the target look to the other player if (tempLookComp) { tempLookComp.targetLook = otherPlayer.transform; } } } playerPieceAnimators[0].SetBool("baseCamper", true); }
private void SetLookAtObject() { if( refLookAtObject != null ) return; if( ReferenceManager.refEnemyLayer.transform.childCount == 0 ) return; int random = Random.Range( 0, ReferenceManager.refEnemyLayer.transform.childCount ); refLookAtObject = LookAtObject.Begin( cachedTransform, ReferenceManager.refEnemyLayer.transform.GetChild( random ), lookSpeed ); refLookAtObject.transform.rotation = cachedTransform.rotation; }
protected override void InitMove() { base.InitMove(); var targetObj = new GameObject( "[ObjectMoveRandomRect] Target" ); target = targetObj.transform; refLookAtObject = LookAtObject.Begin( refTrans, target, 0.1f ); SetTargetPosition(); }
// Use this for initialization void Start() { origScale = transform.localScale; //inject process hit method List <LookAtObject> laoList = new List <LookAtObject>(); LookAtObject lao = GetComponent <LookAtObject>(); lao._processObjectMethodToCall = ProcessObjectAfterFade; }
private static List <PaintingScript> paintings = new List <PaintingScript>(); //list of all instances // Use this for initialization void Start() { //inject process hit method LookAtObject lao = GetComponent <LookAtObject>(); lao._processObjectMethodToCall = ProcessObject; origScale = transform.localScale; paintings.Add(this); }
public override void OnHeartCollide(float heartVal, DetachedPiece thisHeart) { if (catchingIsStopped == false) { if (NextPosFree()) { health += heartVal; if (health > maxHealth) { health = maxHealth; } BlockHealthCheck(); SetHighlight(); thisHeart.collidedOnce = true; LookAtObject newBoiFace = playerBlockParent.GetChild((int)health - 1).GetComponentInChildren <LookAtObject>(); LookAtObject looseBoiFace = thisHeart.GetComponentInChildren <LookAtObject>(); newBoiFace.randomizeFace = false; if (!newBoiFace.alreadyGotSpecialFace) { newBoiFace.GetComponent <SpriteRenderer>().sprite = looseBoiFace.GetComponent <SpriteRenderer>().sprite; } else if (latestFaceProfile != null) { if (!looseBoiFace.alreadyGotSpecialFace) { newBoiFace.SetRandomFace(latestFaceProfile); //asign the lipstick on attachment now i guess } else { newBoiFace.GetComponent <SpriteRenderer>().sprite = looseBoiFace.GetComponent <SpriteRenderer>().sprite; } } Destroy(thisHeart.gameObject); // play Get Piece sound fModGetPieceEvent.start(); if (health > 1 && rotationIndicatorIcon.activeSelf == false) { rotationIndicatorIcon.SetActive(true); } PlayerPieceAnimatorManager animationManager = GetComponent <PlayerPieceAnimatorManager>(); if (animationManager) { //animationManager.ActivateAnimatorTrigger("Catch"); } } } }
GameObject SetUpAutomatedThrowing(Transform stopPos, Vector2 positionThrown) { GameObject pieceThrown = Instantiate(pieceToThrow, positionThrown, Quaternion.identity); foreach (Transform child in pieceThrown.transform) { child.gameObject.layer = LayerMask.NameToLayer("NoPlayerCollision"); } DetachedPiece detachedPieceComp = pieceThrown.GetComponent <DetachedPiece>(); detachedPieceComp.IgnoreColl(playerMoveComp.pieceColliders, true); detachedPieceComp.RevertCollision(); // SET UP POSITION TO LERP TO Vector3 midPos = new Vector3(); midPos.x = stopPos.position.x + (positionThrown.x - stopPos.position.x) / 2; midPos.y = stopPos.position.y + 3f; Vector3[] positions = new Vector3[] { positionThrown, midPos, stopPos.position }; // Set the detatched pieces stopping point detachedPieceComp.SetStoppingDestination(positions); //Rigidbody2D pieceRigidBody = pieceThrown.GetComponent<Rigidbody2D>(); //pieceRigidBody.gravityScale = 0; //temporarily turn off the normal gravity in order to do it manually for the throws //set the face of the new loose boi LookAtObject looseBoiFace = pieceThrown.GetComponentInChildren <LookAtObject>(); looseBoiFace.randomizeFace = false; LookAtObject newBoiFace = playerHealthComp.playerBlockParent.GetChild((int)playerHealthComp.health - 1).GetComponentInChildren <LookAtObject>(); looseBoiFace.GetComponent <SpriteRenderer>().sprite = newBoiFace.GetComponent <SpriteRenderer>().sprite; if (newBoiFace.alreadyGotSpecialFace) { looseBoiFace.alreadyGotSpecialFace = true; } //make them look at the one who dropped them (can change) looseBoiFace.autofindLookTarget = false; looseBoiFace.targetLook = transform; playerHealthComp.OnThrow(); //ENABLE TO DETATCH PIECES return(pieceThrown); }
internal void LookAt(Vector3 position, int duration = 2) { CameraNode.RemoveComponent(nameof(LookAtObject)); var look = CameraNode.CreateComponent <LookAtObject>(); if (look == null) { look = new LookAtObject(camera.Context); } look.PostUpdate = () => { CameraNode.RemoveComponent(look); }; look.TargetPos = position; look.Duration = duration; look.Start(); }
public IEnumerator FillCircularProgress(GameObject selectedObject, bool fadeWithAction) { //set up owner Object LookAtObject lao = selectedObject.GetComponent <LookAtObject>(); ownerObject = lao; // Create a timer and reset the fill amount. float timer = 0f; GameObject mainCamera = Camera.main.gameObject; float perspectiveScale = Vector3.Magnitude(selectedObject.transform.position - mainCamera.transform.position); /* if (mainCamera) { * transform.localScale = transform.localScale * mainCamera.transform.parent.parent.localScale.x * perspectiveScale; * }*/ Image image = gameObject.GetComponent <Image>(); image.fillAmount = 0f; CameraScript cScript = null; Camera cam = null; Vector3 sideVec = Vector3.zero; Kingelez_SceneScript sceneScript = FindObjectOfType <Kingelez_SceneScript>(); if (mainCamera) { cScript = mainCamera.GetComponent <CameraScript>(); cam = mainCamera.GetComponent <Camera>(); sideVec = mainCamera.transform.right; } // This loop is executed once per frame until the timer exceeds the duration. while (timer < selectionDuration && timer >= 0.0f) { //check if progressing to new stage if (sceneScript && sceneScript.disableLookAts) { timer = 0.0f; break; } // The image's fill amount requires a value from 0 to 1 so we normalise the time. image.fillAmount = timer / selectionDuration; bool circularProgressInView = false; Vector3 screenPos3 = cam.WorldToScreenPoint(selectedObject.transform.position); Vector3 screenPos3ForRadius = cam.WorldToScreenPoint(selectedObject.transform.position + sideVec * worldScale * perspectiveScale); //GameObject DebugSphere = GameObject.Find("DebugSphere"); //DebugSphere.transform.position = selectedMarker.transform.position; //DebugSphere.transform.localScale = Vector3.one * worldScale * perspectiveScale; Vector2 screenPos2 = new Vector2(screenPos3.x / cam.pixelWidth, screenPos3.y / cam.pixelHeight); Vector2 screenPos2ForRadius = new Vector2(screenPos3ForRadius.x / cam.pixelWidth, screenPos3ForRadius.y / cam.pixelHeight); float screenRadius = Vector2.Distance(screenPos2, screenPos2ForRadius) * 0.5f; if (Vector2.Distance(screenPos2, new Vector2(0.5f, 0.5f)) < screenRadius) { circularProgressInView = true; } else { circularProgressInView = false; } // Increase the timer by the time between frames and wait for the next frame. if (cScript && (cScript.visibleObject == selectedObject || circularProgressInView)) { timer += Time.deltaTime; } else { timer -= Time.deltaTime; } //transform.position = selectedMarker.transform.position; yield return(null); } // When the loop is finished set the fill amount to be full. if (timer > 0.0f) { image.fillAmount = 1f; //stop circlullar progress routines for other objects CircularProgressScript[] circularProgressScripts = FindObjectsOfType <CircularProgressScript>(); foreach (CircularProgressScript script in circularProgressScripts) { if (script != this) { if (script.ownerObject.circularProgressCoroutine != null) { script.ownerObject.StopCoroutine(script.ownerObject.circularProgressCoroutine); script.ownerObject.circularProgressCoroutine = null; } Destroy(script.gameObject); } } if (lao != null) { if (fadeWithAction) { //check if it a startPlate if (lao.gameObject.GetComponent <StartPlateScript>() != null) { yield return(StartCoroutine(cScript.m_VRCameraFade.FadeWithAction(2.0f, new Color(1, 1, 1, 0), new Color(1, 1, 1, 1), lao._processObjectMethodToCall, parentCanvas))); } else { yield return(StartCoroutine(cScript.m_VRCameraFade.FadeWithAction(fadeDuration, lao._processObjectMethodToCall, parentCanvas))); } } else { lao.ProcessObject(parentCanvas); } } } else { image.fillAmount = 0f; } if (parentCanvas != null) { Destroy(parentCanvas); } if (lao != null) { lao.circularProgressCoroutine = null; } }
// Update is called once per frame void Update() { if (!UnityEngine.XR.XRSettings.isDeviceActive) { UpdateMouseCamera(); } // Show the debug ray if required if (showDebugRay) { Debug.DrawRay(transform.position, transform.forward * debugRayLength, Color.blue, debugRayDuration); } // Create a ray that points forwards from the camera. Ray ray = new Ray(transform.position, transform.forward); RaycastHit hit; visibleObject = null; // Do the spherecast forward to see if we hit an interactive item if (Physics.Raycast(ray, out hit, rayLength, ~m_ExclusionLayers)) { if (m_Reticle) { m_Reticle.SetPosition(hit); } LookAtObject lookAtObject = hit.transform.GetComponent <LookAtObject>(); if (lookAtObject != null) { visibleObject = hit.transform.gameObject; lookAtObject.ProcessHit(); } } else { // Position the reticle at default distance. if (m_Reticle) { m_Reticle.SetPosition(); } } //adaptive resolution if (enableAdaptiveResolution) { float scalingFactor = GetPerformanceScaleFactor(); if (UnityEngine.XR.XRSettings.eyeTextureResolutionScale < maxRenderScale) { // Allocate renderScale to max to avoid re-allocation UnityEngine.XR.XRSettings.eyeTextureResolutionScale = maxRenderScale; } else { // Adjusting maxRenderScale in case app started with a larger renderScale value maxRenderScale = Mathf.Max(maxRenderScale, UnityEngine.XR.XRSettings.eyeTextureResolutionScale); } scalingFactor = Mathf.Clamp(scalingFactor, minRenderScale, maxRenderScale); UnityEngine.XR.XRSettings.eyeTextureResolutionScale = scalingFactor; //VR.VRSettings.renderViewportScale = scalingFactor; //Debug.Log("scaleFactor: " + scalingFactor); } }
GameObject ShootProjectile() { // Generate the object to shot from the player //Vector2 positionThrown = playerHealthComp.playerBlockParent.GetChild((int)playerHealthComp.health - 1).transform.position; //positionThrown.y = Mathf.RoundToInt(positionThrown.y) + .5f; //if grounded Vector2 positionThrown = playerHealthComp.playerBlockParent.GetChild((int)playerHealthComp.health - 1).transform.position; //positionThrown = Movement.RoundVectorToPoint5s(positionThrown); //if (positionThrown.y % 1 == 0) //{ // positionThrown.y += .5f; // print("on the line"); //} positionThrown.y = Mathf.Round(positionThrown.y + .5f) - .5f; GameObject pieceThrown = Instantiate(pieceToThrow, positionThrown, Quaternion.identity); //set the face of the new loose boi LookAtObject looseBoiFace = pieceThrown.GetComponentInChildren <LookAtObject>(); looseBoiFace.randomizeFace = false; LookAtObject newBoiFace = playerHealthComp.playerBlockParent.GetChild((int)playerHealthComp.health - 1).GetComponentInChildren <LookAtObject>(); looseBoiFace.GetComponent <SpriteRenderer>().sprite = newBoiFace.GetComponent <SpriteRenderer>().sprite; if (newBoiFace.alreadyGotSpecialFace) { looseBoiFace.alreadyGotSpecialFace = true; } //make them look at the one who dropped them (can change) looseBoiFace.autofindLookTarget = false; looseBoiFace.targetLook = transform; DetachedPiece detachedPieceComp = pieceThrown.GetComponent <DetachedPiece>(); detachedPieceComp.IgnoreColl(playerMoveComp.pieceColliders, true); detachedPieceComp.RevertCollision(); //Get the Vectpr to fire the piece from Transform playerHead = playerHealthComp.playerBlockParent.GetChild((int)playerHealthComp.health - 1); Vector3 fireDirectionVector = (rotationIndicatorIcon.transform.position - playerHead.position).normalized; CalculateThrow(); // Calculate the shot velocity and gravity depending on the incial launch angle Rigidbody2D pieceRigidBody = pieceThrown.GetComponent <Rigidbody2D>(); pieceRigidBody.velocity = new Vector2(currentThrow.startingVelocity.x * rotationIndicatorInput.x, currentThrow.startingVelocity.y * Mathf.Sign(rotationIndicatorInput.y)); pieceRigidBody.gravityScale = 0; //temporarily turn off the normal gravity in order to do it manually for the throws detachedPieceComp.gravity = currentThrow.gravity; detachedPieceComp.hasLanded = false; if (currentThrow == throwingProfile.horizontals) { detachedPieceComp.SetTimeFromSpeedAndDistance(currentThrow.xDistance); } playerHealthComp.OnThrow(); //ENABLE TO DETATCH PIECES // Play Throw Sound fModThrowPieceEvent.start(); //throwScreamEvent.start(); return(pieceThrown); }
// Use this for initialization void Start() { moonFace = GetComponent <LookAtObject>(); cig = GameObject.Find("Cig"); lipstick = GameObject.Find("Lipstick"); }
// Use this for initialization public override void Start() { base.Start(); refLookAtObject = LookAtObject.Begin( Trans, ReferenceManager.Player.transform, lookSpeed ); }