public bool canRiseInMinTime(float timeToRise, BulletLauncher user) { if (!isOnTheSameGroundOfTheUser()) { m_heightToReach = transform.position.y; } else { m_heightToReach = transform.position.y + m_size.y; } int nbFrameToDo = (int)(timeToRise / Time.deltaTime); float timePerFrame = timeToRise / nbFrameToDo; Vector3 force = m_gravityForce + Vector3.up * m_forceUp * getDistanceRatio(user); Vector3 acceleration = force / m_rigidBody.mass; float heightTraveled = 0; float speed = 0; for (int i = 0; i < nbFrameToDo; ++i) { speed += acceleration.y * timePerFrame; heightTraveled += speed * timePerFrame; } return(transform.position.y + heightTraveled >= m_heightToReach); }
public void setUser(string _playerID) { if (_playerID.Contains("FakePlayer")) { launcher = GameObject.Find(_playerID).GetComponent <BulletLauncher>(); } }
void setStateAvailable() { m_heightToReach = transform.position.y; m_risingStarted = true; m_risingDone = true; m_flingDone = true; m_user = null; launcher = null; }
// Themes are loaded at loadType = "Level", anything not in the dictionary is loaded at loadType = "Map" public void LoadProperties(Level level, string loadType) { foreach (var json in objects) { string type = (string)json["Type"]; if (loadType == (loadTypes.ContainsKey(type)? loadTypes[type] : "Map")) { switch (type) { case "Level": level.LevelName = (string)json["Name"]; level.NextLevel = (string)json["NextLevel"]; level.Theme = Theme.GetTheme((string)json["Theme"]); if (level.Theme.Name == "Space") { level.Gravity = .15f; } break; case "Castle": BlockEntity castle = (BlockEntity)(level.Map.blockGrid[(int)json["X"], (int)json["Y"]]); castle.BoundingBox.Active = !(bool)(json["AtBeginning"] ?? false); break; case "Theme": level.Theme = Theme.GetTheme((string)json["Theme"]); break; case "Pipe": PipeState pipe = (PipeState)(level.Map.blockGrid[(int)json["X"], (int)json["Y"]].BlockStates.State); pipe.StoredLevel = (string)json["Destination"]; pipe.Destination = new Point((int)json["DestX"], (int)json["DestY"]); pipe.Return = (bool)(json["Return"] ?? true); break; case "Firebar": Firebar bar = (Firebar)(level.Map.blockGrid[(int)json["X"], (int)json["Y"]].BlockStates.State); bar.Size = (int)json["Size"]; bar.Clockwise = (bool)json["Clockwise"]; break; case "Launcher": BulletLauncher launcher = (BulletLauncher)(level.Map.blockGrid[(int)json["X"], (int)json["Y"]].BlockStates.State); launcher.BulletType = (Mobs)Enum.Parse(typeof(Mobs), (string)json["BulletType"]); break; case "BLauncher": BanzaiLauncher launcher1 = (BanzaiLauncher)(level.Map.blockGrid[(int)json["X"], (int)json["Y"]].BlockStates.State); launcher1.BulletType = (Mobs)Enum.Parse(typeof(Mobs), (string)json["BulletType"]); launcher1.flipped = ((int)json["Flip"]) == 1; break; } } } }
// Start is called before the first frame update void Start() { // launcher = Instantiate(launcherPrefab); // launcher.SetGameController(new KeyGameController()); launcher = new BulletLauncher(new KeyGameController()); MouseGameController mouseController = gameObject.AddComponent <MouseGameController>(); // mouseController.FireButtonPressed += launcher.OnFireButtonPressed; }
/// <summary> /// 激活技能 /// </summary> public void Active(Unit unit, float direction, Unit targetUnit) { this.activeUnit = unit; this.targetUnit = targetUnit; this.direction = direction; for (int i = 0; i < skillParser.launcherList.Length; i++) { BulletLauncher launcher = PoolMgr.Inst.SpawnObj <BulletLauncher>(); launcher.Init(this, skillParser.launcherList[i]); } }
void Start() { launcher = Instantiate(launcherPrefab); launcher.transform.position = launcherLocator.position; mouseGameController = gameObject.AddComponent <MouseGameController>(); buildingManager = new BuildingManager(buildingPrefab, buildingLocators, new Factory(effectPrefab)); timeManager = gameObject.AddComponent <TimeManager>(); missileManager = gameObject.AddComponent <MissileManager>(); missileManager.Initialize(new Factory(missilePrefab), buildingManager, maxMissileCount, missileSpawnInterval); scoreManager = new ScoreManager(scorePerMissile, scorePerBuilding); BindEvents(); timeManager.StartGame(1f); }
// Start is called before the first frame update void Start() { character = GetComponentInParent <Character>(); bL = GetComponentInChildren <BulletLauncher>(); }
// Start is called before the first frame update void Start() { launcher = Instantiate(launcherPrefab); //launcher.SetGameController(new MouseGameController()); launcher.SetGameController(new KeyGameController()); }
void Start() { player = gameObject.GetComponent <Player>(); movingCamera = Camera.main.transform; launcher = GetComponent <BulletLauncher>(); }
float getDistanceRatio(BulletLauncher _user) { float ratio = _user.m_OffsetForwardEarth / Vector3.Distance(transform.position, _user.transform.position); return(Mathf.Min(4 * ratio, 1)); }
virtual protected void FixedUpdate() { // Cheat if (Input.GetKeyDown(KeyCode.Z)) { Destroy(this.gameObject); } if (m_launcher) { fire = m_launcher.isKey(); } m_forceTotal = m_gravityForce; bool heightReached = transform.position.y >= m_heightToReach; // Update Underground { RaycastHit hit; m_isUnderground = Physics.Raycast(m_collider.bounds.center, Vector3.up, out hit, 50) && hit.collider.gameObject.name.Contains("Terrain"); if (!m_isUnderground && m_wasUnderground) { Instantiate(m_smokeStartToMove, transform.position, Quaternion.identity); Physics.IgnoreLayerCollision(gameObject.layer, Manager.getManager().m_terrain.gameObject.layer, false); } } if (!m_risingStarted && !heightReached && m_user != null) { rise(); m_risingStarted = true; } else if (!m_risingDone && !heightReached && (!launcher && fire || launcher && fireCheat)) { rise(); } else if (!m_risingDone && !heightReached) { setStateAvailable(); } else if (!m_risingDone && heightReached) { m_rigidBody.velocity = new Vector3(m_rigidBody.velocity.x, 0.0f, m_rigidBody.velocity.z); m_risingDone = true; } else if (m_risingDone && !m_flingDone) { if (fire) { stabilize(); } else { m_rigidBody.velocity = new Vector3(m_rigidBody.velocity.x, 0.0f, m_rigidBody.velocity.z); Ray ray = m_user.GetComponent <AttackLauncher>().getAimRay(); Debug.DrawRay(ray.origin, ray.direction, Color.blue); //UnityEditor.EditorApplication.isPaused = true; RaycastHit hit = new RaycastHit(); RaycastHit[] hitList = Physics.RaycastAll(ray, 5000); // Do not take in account this.gameobject as aim if (hitList.Length < 1) { hit.point = ray.direction * 5000; } else if (!hitList[0].collider.gameObject.name.Contains(gameObject.name)) { hit = hitList[0]; } else if (hitList.Length < 2) { hit.point = ray.direction * 5000; } else { hit = hitList[1]; } m_forward = hit.point - transform.position; m_forward.Normalize(); m_forceTotal += m_forward * m_forceForward * getDistanceRatio(); stabilize(); m_flingDone = true; m_user = null; launcher = null; } } if (m_risingDone && isGrounded()) { if (m_rigidBody.velocity.magnitude > m_minSpeedStop) { m_forceTotal += -m_rigidBody.velocity.normalized * m_earthFriction; } else { m_rigidBody.velocity = Vector3.zero; } if (m_rigidBody.angularVelocity.magnitude > m_minAngularSpeedStop) { m_forceTotal += -m_rigidBody.angularVelocity.normalized * m_earthFriction; } else { m_rigidBody.angularVelocity = Vector3.zero; } } m_rigidBody.AddForce(m_forceTotal); m_wasUnderground = m_isUnderground; m_previousPos[1] = m_previousPos[0]; m_previousPos[0] = transform.position; }
void Awake() { launcher = GetComponent <BulletLauncher>(); animator = GetComponent <Animator>(); }