private void Init() { Time.timeScale = 1.0f; gamePaused = false; m_prevPlatform = m_firstJumpPoint; m_nextPlatform = m_firstJumpPoint.GetComponent <PlatformJumpPointView>().NextPlatform; transform.position = m_firstJumpPoint.Position + Vector3.up; SetLookTarget(m_nextPlatform, m_nextPlatform); LookTargetSmooth = m_nextPlatform.Position; transform.LookAt(LookTargetSmooth); var current = m_firstJumpPoint.GetComponent <PlatformJumpPointView>(); while (current != null) { if (current.NextPlatform != null) { current.NextPlatform.GetComponent <PlatformJumpPointView>().PrevPlatform = current; current = current.NextPlatform.GetComponent <PlatformJumpPointView>(); } else { current = null; } } gameMusic.Play(); }
void Update() { if (m_died) { return; } if (m_isFallingDown) { var positon = transform.position; m_fallingDownVelocity += GravityVector * Time.deltaTime; positon += m_fallingDownVelocity * Time.deltaTime; transform.position = positon; Quaternion rollRotation = Quaternion.AngleAxis(m_rollAngleSpeed * Time.deltaTime, transform.forward); transform.rotation = rollRotation * transform.rotation; if (transform.position.y < 0 && !m_died) { m_died = true; OnDied.Invoke(); return; } return; } if (transform.position.y < 0 && !m_died) { GameAnalyticsSDK.GameAnalytics.NewProgressionEvent(GameAnalyticsSDK.GAProgressionStatus.Complete, "level 1", PlatformsScored); m_died = true; OnDied.Invoke(); return; } if ((Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space) || (!m_started && m_autoJump)) && !gamePaused) { if (m_canJump) { if (!m_started) { Jump(m_prevPlatform.NativePosition, 0.001f, 45.0f * Mathf.Deg2Rad); m_started = true; GameAnalyticsSDK.GameAnalytics.NewProgressionEvent(GameAnalyticsSDK.GAProgressionStatus.Start, "level 1", 0); } else { AirJump(); } m_canJump = false; } else { UnityEngine.RaycastHit hit; UnityEngine.Ray ray = HUDCamera.ScreenPointToRay(Input.mousePosition); if (UnityEngine.Physics.Raycast(ray, out hit)) { if (hit.transform.tag == "Clickable") { var t_TargetTrigger = hit.transform.gameObject.GetComponent <TargetTrigger>(); t_TargetTrigger.NotifyHit(); } } } } if (Input.GetKeyDown(KeyCode.Escape)) { if (gamePaused) { gameLeave(); } else { gamePause(); } } if (!m_started) { return; } m_horizontalDistance += m_horizontalSpeed * Time.deltaTime; float height = Physics.GetHeightAtDistance(0, m_jumpAngle, m_horizontalDistance, m_jumpSpeed); var position = m_jumpPosition; position += m_horizontalDirection * m_horizontalDistance; position.y += height; UpdateSmoothLookTarget(); transform.position = position; transform.LookAt(LookTargetSmooth); if (m_autoJump && m_horizontalDistance >= m_prevPlatform.GetComponent <PlatformJumpPointView>().AirJumpOnDistance&& m_canJump) { AirJump(); m_canJump = false; } }