private void AssignParts() { Transform prefab = transform.GetChild(0); for (int i = 0; i < prefab.childCount; i++) { if (prefab.GetChild(i).name == "ES_Top") { spawnPointTop = prefab.GetChild(i); spawnPointTop.localPosition = new Vector3(0, -4, 0); break; } } for (int i = 0; i < spawnPointTop.childCount; i++) { if (spawnPointTop.GetChild(i).name == "ES_Lights") { spawnPointLights = spawnPointTop.GetChild(i); } if (spawnPointTop.GetChild(i).name == "ES_Lift") { spawnLift = spawnPointTop.GetChild(i); spawnLiftGroundCollider = spawnLift.GetComponent <GroundCollider> (); } if (spawnPointTop.GetChild(i).name == "ES_Rods") { rodsBoxCollider = spawnPointTop.GetChild(i).GetComponent <BoxCollider> (); } } }
public void CheckGround() { Vector3 start = transform.position; Vector3 end = start + new Vector3(0, -1f, 0); boxCollider.enabled = false; RaycastHit hitInfo; if (Physics.Linecast(start + groundOffset, end + groundOffset, out hitInfo, groundLayerMask)) { transform.parent = hitInfo.transform; if (setFirstParent) { parentGroundCollider = hitInfo.transform.GetComponent <GroundCollider> (); parentGroundCollider.occupied = true; setFirstParent = false; } else { if (targetGroundCollider) { parentGroundCollider = targetGroundCollider; } } idle = true; if (hitInfo.transform.tag == "MovingPlatform") { onMovingPlatform = true; horizontal = 0; vertical = 0; } else if (hitInfo.transform.tag == "ChangeDirection") { horizontal = prevHorizontal * -1; vertical = prevVertical * -1; skipTurn = true; } else if (hitInfo.transform.tag == "SlidingPlatform") { IDriveableTile slidingTileScript = parentGroundCollider.levelTile.GetComponent <IDriveableTile> (); horizontal = slidingTileScript.GetHorizontal(); vertical = slidingTileScript.GetVertical(); skipTurn = true; myAnimator.SetTrigger("Idle"); onSlidingGround = true; moveTime = slidingTileScript.GetMoveSpeed(); } else if (hitInfo.transform.tag == "ButtonTile") { parentGroundCollider.levelTile.GetComponent <ISwitchable> ().SwitchOn(); } } else { Falling(); } boxCollider.enabled = true; }
private void AssignParts() { Transform prefab = transform.GetChild(0); for (int i = 0; i < prefab.childCount; i++) { if (prefab.GetChild(i).name == "Button") { button = prefab.GetChild(i).transform; break; } } myGroundCollider = button.GetComponent <GroundCollider> (); }
protected virtual void CharacterDead() { if (parentGroundCollider) { parentGroundCollider.occupied = false; parentGroundCollider = null; } if (targetGroundCollider) { targetGroundCollider.occupied = false; targetGroundCollider = null; } transform.parent = null; Destroy(gameObject); }
private bool HasGround(Vector3 end) { boxCollider.enabled = false; RaycastHit hitInfo; if (Physics.Linecast(end + groundOffset, end + new Vector3(0, -1f, 0) + groundOffset, out hitInfo, groundLayerMask)) { GroundCollider targetGroundCollider = hitInfo.transform.GetComponent <GroundCollider> (); if (targetGroundCollider && targetGroundCollider.occupied == false && targetGroundCollider.tag != "MovingPlatform") { return(true); } } return(false); }
//Called to get that little compression when the player lands /**private IEnumerator ScaleDown() { * float timeToScaleDown = moveTime * 0.5f; * float _jumpCompression = jumpCompression * (jumpHeight / jumpCompressionBaseHeight); * for (float t = 0; t < 1; t += Time.deltaTime / timeToScaleDown) * { * if (jumping == false) { * characterBase.localScale = new Vector3 (characterBase.localScale.x, * characterBaseScaleY * (1 - (_jumpCompression * Mathf.Sin (Mathf.PI * t))), * characterBase.localScale.z); * } else { * t = 1; * characterBase.localScale = new Vector3(characterBase.localScale.x, characterBaseScaleY, characterBase.localScale.z); * } * yield return null; * } * characterBase.localScale = new Vector3(characterBase.localScale.x, characterBaseScaleY, characterBase.localScale.z); * } **/ private IEnumerator SmoothMovement(Vector3 start, Vector3 end) { Vector3 moveDirection = (end - start); float t = 0; for (t = Time.deltaTime / moveTime; t < 1; t += Time.deltaTime / moveTime) { if (jump) { characterBase.localPosition = new Vector3(0, jumpHeight * Mathf.Sin(Mathf.PI * t), 0); } transform.localPosition = start + (moveDirection * t); if (t > 0.5f) { if (parentGroundCollider) { parentGroundCollider.occupied = false; parentGroundCollider = null; } } yield return(null); } if (jump) { characterBase.localPosition = Vector3.zero; } if (movementStyle == MovementStyle.CONTINUOS_WALK) { if (t - 1 < Time.deltaTime / moveTime && t - 1 > 0) { transform.localPosition = start + (moveDirection * t); } } else { transform.localPosition = start + (moveDirection * 1); } moveTime = originalMoveTime; CheckGround(); }
public virtual void Initialize() { if (myPrefab == null) { if (transform.childCount == 0) { #if UNITY_EDITOR if (Application.isPlaying == false) { myPrefab = PrefabUtility.InstantiatePrefab(levelTilePrefab) as Transform; } else { //myPrefab = (Transform)Instantiate (levelTilePrefab, Vector3.zero, Quaternion.identity); myPrefab = TVNTObjectPool.instance.SpawnObject(levelTilePrefab); } #else //myPrefab = (Transform) Instantiate(levelTilePrefab, Vector3.zero, Quaternion.identity); myPrefab = TVNTObjectPool.instance.SpawnObject(levelTilePrefab); #endif myPrefab.parent = transform; myPrefab.localPosition = Vector3.zero; myPrefab.localRotation = Quaternion.identity; myPrefab.localScale = new Vector3(Mathf.Abs(myPrefab.localScale.x), Mathf.Abs(myPrefab.localScale.y), Mathf.Abs(myPrefab.localScale.z)); myPrefab.gameObject.SetActive(true); } else { myPrefab = transform.GetChild(0); myPrefab.localPosition = Vector3.zero; myPrefab.localRotation = Quaternion.identity; myPrefab.localScale = new Vector3(Mathf.Abs(myPrefab.localScale.x), Mathf.Abs(myPrefab.localScale.y), Mathf.Abs(myPrefab.localScale.z)); myPrefab.gameObject.SetActive(true); } } GroundCollider groundCollider = transform.GetComponentInChildren <GroundCollider> (); if (groundCollider) { groundCollider.levelTile = transform; } }
private bool OccupyMoveToTile(Vector3 end) { boxCollider.enabled = false; RaycastHit hitInfo; if (Physics.Linecast(end + groundOffset, end + new Vector3(0, -1f, 0) + groundOffset, out hitInfo, groundLayerMask)) { targetGroundCollider = hitInfo.transform.GetComponent <GroundCollider> (); if (targetGroundCollider.occupied == false) { targetGroundCollider.occupied = true; return(true); } else { targetGroundCollider = null; return(false); } } targetGroundCollider = null; return(true); }