protected override void basicAttack4() { Ray ray = GetComponent <AttackLauncher>().getAimRay(); RaycastHit hit; bool collided = Physics.Raycast(ray, out hit, 5000); BreakableRock breakableRock = hit.collider.GetComponentInParent <BreakableRock>(); if (Physics.Raycast(ray, out hit, 5000)) { if (collided && breakableRock != null) { breakableRock.breakRock(gameObject, m_launcher, m_attack1ForceUp, m_attack1ForceForward); } else { Quaternion rotation = Quaternion.FromToRotation(transform.up, hit.normal) * Quaternion.FromToRotation(m_attack4Object.transform.forward, transform.forward); Vector3 newDirection = rotation * m_attack4Object.transform.up; float ySize = 0; for (int i = 0; i < m_attack4Object.transform.childCount; ++i) { MeshRenderer meshRenderer = m_attack4Object.transform.GetChild(i).GetComponent <MeshRenderer>(); ySize += meshRenderer.bounds.size.y; } Vector3 vect = newDirection * ySize / 2.0f; Instantiate(m_attack4Object, hit.point - vect, rotation); m_executingAtk4 = true; } } }
private void basicAttack1() { AttackLauncher atkLauncher = GetComponent <AttackLauncher>(); Ray ray = atkLauncher.getAimRay(); RaycastHit hit; bool collided = Physics.Raycast(ray, out hit, 5000); BreakableRock breakableRock = null; if (hit.collider) { breakableRock = hit.collider.GetComponentInParent <BreakableRock>(); } if (Physics.Raycast(ray, out hit, 5000)) { if (collided && breakableRock != null) { breakableRock.breakRock(gameObject, GetComponent <AttackLauncher>(), m_attack1ForceUp, m_attack1ForceForward); } else { Collider[] colliders = Physics.OverlapSphere(transform.position, m_rangeToTakeBullet); FlingableRock bullet = null; if (colliders.Length > 0) { bullet = findBullet(colliders); if (!bullet) { spawnAndFlingBullet(GetComponent <AttackLauncher>(), m_attack1ForceUp, m_attack1ForceForward); } else { // GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); // sphere.transform.position = transform.position; // sphere.transform.localScale = new Vector3(1, 1, 1) * m_rangeToTakeBullet; // sphere.GetComponent<SphereCollider>().enabled = false // UnityEditor.EditorApplication.isPaused = true; bullet.setUser(gameObject); myCurrentBullet = bullet; bullet.fling(GetComponent <AttackLauncher>(), m_attack1ForceUp, m_attack1ForceForward, false); } } else { spawnAndFlingBullet(GetComponent <AttackLauncher>(), m_attack1ForceUp, m_attack1ForceForward); } } } GetComponent <BasicMovement>().m_Animator.Play("Attack 01"); GetComponent <BasicMovement>().m_Animator.CrossFade("Grounded", 1f); }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.GetComponent <IBreakable>() != null) { if (collision.gameObject.GetComponent <BreakableRock>() != null) { BreakableRock br = collision.gameObject.GetComponent <BreakableRock>(); MineRecorder.UpdateMineTileHealth(br.floorNumber, br.mineType, -1, br.index); if (MineRecorder.GetMineTileHealth(br.floorNumber, br.mineType, br.index) <= 0) { if (GameData.Instance.playerOreSupplies[PlayerID].ContainsKey(br.tileType)) { mrm.CollectResource(br.tileType, br.myTile.oreAmount); } br.Break(); } } } }
public void OnRockBroken(BreakableRock rock) { foreach (var item in rocksToBreak) { if (item.B == rock) { item.A = true; } } GameObject go = Instantiate(breakPrefab); go.transform.localScale = rock.transform.lossyScale; go.transform.position = rock.transform.position; go.transform.rotation = rock.transform.rotation; Destroy(rock.gameObject); if (IsFinished) { GameManager.Instance.OnWin(); } }
// LD 29 specific static void SetObjectType(GameObject obj, Collider2D collider) { UTiledProperties properties = obj.GetComponent <UTiledProperties>(); if (properties != null) { switch (properties.ObjectType) { case "Lava": obj.AddComponent <LavaTile>(); obj.tag = "Lava"; break; case "RockMonster": obj.AddComponent <RockMonsterSpawner>(); break; case "Ruby": obj.tag = "Ruby"; collider.isTrigger = true; break; case "Giant": Giant g = obj.AddComponent <Giant>(); g.NewLevel = properties.GetValue("NewLevel"); int?rg = properties.GetValueAsInt("RubyGoal"); g.RubyGoal = rg.HasValue ? rg.Value : 1; break; case "BreakRock": BreakableRock br = obj.AddComponent <BreakableRock>(); br.Contains = properties.GetValue("Contains"); Vector2 tmpVector = ((BoxCollider2D)collider).size; tmpVector.x = 0.5f; ((BoxCollider2D)collider).size = tmpVector; break; } } }
private void DrawGrid() { float x = _adjustedX; float y = _adjustedY; _tilesInScene = new GameObject[_gridHeight * _gridWidth]; //Create Blanks for (int i = 0; i < _tiles.Length; i += _gridWidth) { for (int j = 0; j < _gridWidth; j++) { Tile currentTile = _tiles[i + j]; GameObject prefabToGenerate = _blankTile; GameObject go = Instantiate(prefabToGenerate, new Vector3(0, 0, 0), Quaternion.identity); SpriteRenderer sr = go.GetComponent <SpriteRenderer>(); if (mineType == Mine.IronMine) { sr.color = _ironFloor; } if (mineType == Mine.JellyMine) { sr.color = _jellyFloor; } if (mineType == Mine.CoalMine) { sr.color = _coalFloor; } go.transform.parent = transform; go.transform.position = new Vector3(x, y, 0); if (currentTile.tileType == TileType.Spawn) { _playerObject.transform.position = new Vector3(x, y, 0); } x += _tileWidth; } x = _adjustedX; y += _tileWidth; } x = _adjustedX; y = _adjustedY; //Create other objects for (int i = 0; i < _tiles.Length; i += _gridWidth) { for (int j = 0; j < _gridWidth; j++) { Tile currentTile = _tiles[i + j]; GameObject prefabToGenerate = _blankTile; if (currentTile.tileType == TileType.Rock) { prefabToGenerate = _rockTile; } else if (currentTile.tileType == TileType.Stair) { prefabToGenerate = _stairTile; } else if (currentTile.tileType == TileType.Iron) { prefabToGenerate = _ironTile; } else if (currentTile.tileType == TileType.Food) { prefabToGenerate = _jellyTile; } else if (currentTile.tileType == TileType.Hole) { prefabToGenerate = _holeTile; } else if (currentTile.tileType == TileType.Coal) { prefabToGenerate = _coalTile; } else if (currentTile.tileType == TileType.Diamond) { prefabToGenerate = _diamondTile; } if (prefabToGenerate != _blankTile) { GameObject go = Instantiate(prefabToGenerate, new Vector3(0, 0, 0), Quaternion.identity); SpriteRenderer sr = go.GetComponent <SpriteRenderer>(); BreakableRock r = go.GetComponent <BreakableRock>(); if (r != null) { r.CreateSettings(currentTile.oreAmount, currentTile.health, _currentFloor, mineType, i + j, currentTile); } go.transform.parent = transform; go.transform.position = new Vector3(x, y, 0); if (currentTile.tileType == TileType.Spawn) { _playerObject.transform.position = new Vector3(x, y, 0); } _tilesInScene[i + j] = go; } x += _tileWidth; } x = _adjustedX; y += _tileWidth; } if (_currentFloor == 0) { SetElevators(); } }
public void RegisterRock(BreakableRock go) { rocksToBreak.Add(new Pair <bool, BreakableRock>(false, go)); }
protected override void basicAttack3() { Ray ray = GetComponent <AttackLauncher>().getAimRay(); RaycastHit hit; bool collided = Physics.Raycast(ray, out hit, 5000); BreakableRock breakableRock = hit.collider.GetComponentInParent <BreakableRock>(); if (Physics.Raycast(ray, out hit, 5000)) { if (collided && breakableRock != null) { breakableRock.breakRock(gameObject, m_launcher, m_attack1ForceUp, m_attack1ForceForward); } else { Quaternion xAndzRotation; if (transform.up == Vector3.up || transform.up == -Vector3.up) { xAndzRotation = Quaternion.FromToRotation(transform.up + Vector3.forward * 0.01f, hit.normal + Vector3.forward * 0.01f); } else if (transform.up == Vector3.right || transform.up == -Vector3.right || transform.up == Vector3.forward || transform.up == -Vector3.forward) { xAndzRotation = Quaternion.FromToRotation(transform.up + Vector3.up * 0.01f, hit.normal + Vector3.up * 0.01f); } else { xAndzRotation = Quaternion.FromToRotation(transform.up, hit.normal); } Quaternion yRotation; if (transform.forward == Vector3.forward || transform.forward == -Vector3.forward) { yRotation = Quaternion.FromToRotation(m_attack3Object.transform.forward + Vector3.right * 0.01f, transform.forward + Vector3.right * 0.01f); } else if (transform.forward == Vector3.right || transform.forward == -Vector3.right || transform.forward == Vector3.up || transform.forward == -Vector3.up) { yRotation = Quaternion.FromToRotation(m_attack3Object.transform.forward + Vector3.forward * 0.01f, transform.forward + Vector3.forward * 0.01f); } else { yRotation = Quaternion.FromToRotation(m_attack3Object.transform.forward, transform.forward); } Quaternion rotation = xAndzRotation * yRotation; Vector3 newDirection = rotation * m_attack3Object.transform.up; float ySize = 0; for (int i = 0; i < m_attack3Object.transform.childCount; ++i) { MeshRenderer meshRenderer = m_attack3Object.transform.GetChild(i).GetComponent <MeshRenderer>(); ySize += meshRenderer.bounds.size.y; } Vector3 vect = newDirection * ySize / 2.0f; Instantiate(m_attack3Object, hit.point - vect, rotation); m_executingAtk3 = true; } } m_Animator.Play("Attack 03"); m_Animator.CrossFade("Grounded", 1f); }
protected override void basicAttack2() { Ray ray = GetComponent <AttackLauncher>().getAimRay(); RaycastHit hit = new RaycastHit(); bool collided = Physics.Raycast(ray, out hit, 5000); BreakableRock breakableRock = hit.collider.GetComponentInParent <BreakableRock>(); if (collided && breakableRock != null) { breakableRock.breakRock(gameObject, m_launcher, m_attack1ForceUp, m_attack1ForceForward); } else { if (!collided) { hit.point = ray.direction * 5000; } Vector3 direction = hit.point - transform.position; direction.Normalize(); RaycastHit hitGround; { Vector3 origin = transform.position + transform.forward * m_OffsetForwardEarth * 4; if (!Physics.Raycast(origin, -Vector3.up, out hitGround, 50)) { Physics.Raycast(origin, Vector3.up, out hitGround, 50); } } if (!hitGround.collider.gameObject.name.Contains("Terrain")) { return; } // Debug.DrawRay(hitGround.point, transform.up, Color.blue); // Debug.DrawRay(hitGround.point, hitGround.normal, Color.cyan); // Debug.DrawRay(hitGround.point, m_attack2Object.transform.forward, Color.red); // Debug.DrawRay(hitGround.point, transform.forward, Color.magenta); // UnityEditor.EditorApplication.isPaused = true; Quaternion xAndzRotation; if (transform.up == Vector3.up || transform.up == -Vector3.up) { xAndzRotation = Quaternion.FromToRotation(transform.up + Vector3.forward * 0.01f, hitGround.normal + Vector3.forward * 0.01f); } else if (transform.up == Vector3.right || transform.up == -Vector3.right || transform.up == Vector3.forward || transform.up == -Vector3.forward) { xAndzRotation = Quaternion.FromToRotation(transform.up + Vector3.up * 0.01f, hitGround.normal + Vector3.up * 0.01f); } else { xAndzRotation = Quaternion.FromToRotation(transform.up, hitGround.normal); } Quaternion yRotation; if (transform.forward == Vector3.forward || transform.forward == -Vector3.forward) { yRotation = Quaternion.FromToRotation(m_attack2Object.transform.forward + Vector3.right * 0.01f, transform.forward + Vector3.right * 0.01f); } else if (transform.forward == Vector3.right || transform.forward == -Vector3.right || transform.forward == Vector3.up || transform.forward == -Vector3.up) { yRotation = Quaternion.FromToRotation(m_attack2Object.transform.forward + Vector3.forward * 0.01f, transform.forward + Vector3.forward * 0.01f); } else { yRotation = Quaternion.FromToRotation(m_attack2Object.transform.forward, transform.forward); } Quaternion rotation = xAndzRotation * yRotation; Instantiate(m_attack2Object, hitGround.point, rotation); m_Animator.Play("Attack 02"); m_Animator.CrossFade("Grounded", 1f); } }
// Use this for initialization void Start() { Rock = transform.parent.GetComponent <BreakableRock>(); }