public static void LoadCollectables() { AllHostages = new List <Hostage>(); UnlockedHostages = new List <Hostage>(); //Grab all hostage file var hostages = Resources.LoadAll <TextAsset>("Hostages"); //Convert text -> hostage and store data foreach (TextAsset hostage in hostages) { Hostage obj = JsonUtility.FromJson <Hostage>(hostage.text); AllHostages.Add(obj); Debug.Log("Loading - hostage:" + obj.id); } //Load unlocks from PlayerPrefs string unlockString = PlayerPrefs.GetString("unlocks", "json,richard,mike"); string[] unlocks = unlockString.Split(','); foreach (string unlock in unlocks) { foreach (Hostage hostage in AllHostages) { if (unlock == hostage.id) { UnlockedHostages.Add(hostage); break; } } } Debug.Log("Player Unlocks: " + unlockString); }
protected override void OnTriggerEnter2D(Collider2D collision) { base.OnTriggerEnter2D(collision); hostage = collision.GetComponent <Hostage>(); if (hostage != null) { hostage.SetDestination(hostageLocation); } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "Player") { int findCount = 0; foreach (string unlock in unlocks) { foreach (Hostage hostage in Collectables.UnlockedHostages) { if (hostage.id == unlock) { findCount++; break; } } } if (findCount < unlocks.Length - 1) { Hostage unlockThisOne = null; while (unlockThisOne == null) { string unlock = unlocks[Random.Range(0, unlocks.Length - 1)]; bool alreadyUnlocked = false; foreach (Hostage hostage in Collectables.UnlockedHostages) { if (hostage.id == unlock) { alreadyUnlocked = true; break; } } if (alreadyUnlocked == false) { foreach (Hostage hostage in Collectables.AllHostages) { if (hostage.id == unlock) { unlockThisOne = hostage; } } if (unlockThisOne == null) { Debug.LogError("hostage:" + unlock + " does not exists!"); break; } manager.UnlockNewHostage(unlockThisOne); } } } Destroy(gameObject); } }
private void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.CompareTag("Hostage") && capture == null) { capture = other.gameObject; Hostage hostage = other.gameObject.GetComponent <Hostage>(); hostage.SetTrapped(true); hostage.transform.position = transform.position; hostage.GetPlayer().GetComponent <Player>().SaveHostage(); } }
public void UnlockNewHostage(Hostage hostage) { CloseHostageDisplay(); unlockInfoDisplay.transform.Find("Name").GetComponent <Text>().text = hostage.name; unlockInfoDisplay.transform.Find("Image").GetComponent <Image>().sprite = hostage.getSprite(); unlockInfoDisplay.transform.Find("Backstory").GetComponent <Text>().text = hostage.background; Collectables.UnlockedHostages.Add(hostage); Collectables.SaveCollectables(); UnpauseGame(false); unlockInfoDisplay.SetActive(true); }
private void InitilizeHostage(Vector3 startPos) { // 管理オブジェクトを生成 Hostage.parent = new TokenMgr <Hostage>("Hostage", 1); //Vector3 startPos = stageList[startPosInd].obj.transform.position; hostage = Hostage.Add(0, playerMoveSpeed, startPos, this, player); StartCoroutine(InitilizeEffect(hostage.transform.position, hostageEffect)); //Follow.objTarget = p.gameObject; }
private void OnCollisionEnter2D(Collision2D col) { Hostage hostage = col.collider.GetComponent <Hostage>(); if (hostage != null) { hostage.ammo += ammo; box.enabled = false; sr.enabled = false; thing.Die(); source.PlayOneShot(sound); } }
public void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "Wall") { // Instantiate(impactEffect, transform.position, Quaternion.identity); Destroy(gameObject); } else if (other.gameObject.tag == "Hostage") { int hstID = other.gameObject.GetComponent <Hostage>().ID; Hostage selectedHst = Hostage.currentHostages.Where(h => h.ID == hstID).FirstOrDefault(); selectedHst.GetInjured(); } }
public static Hostage Add(int id, float move_speed, Vector3 pos, GameMgr gm, Player player) { Hostage hostage = parent.Add(pos.x, pos.y + 1, pos.z); hostage.SetParam(id); hostage.SetMoveSpeed(move_speed); hostage.SetGmaeMgr(gm); hostage.SetPlayer(player); return(hostage); }
void DisplayHostage(Hostage hostage) { Transform info = transform.Find("Info"); info.Find("Name").GetComponent <Text>().text = hostage.name; info.Find("Image").GetComponent <Image>().sprite = hostage.getSprite(); info.Find("Backstory").GetComponent <Text>().text = hostage.background; info.transform.Find("Mass").GetComponent <Text>().text = "Mass: " + hostage.mass.ToString(); info.transform.Find("Slip").GetComponent <Text>().text = "Slip: " + ((1 - hostage.friction) * 10).ToString(); for (int i = 0; i < info.transform.Find("HP").childCount; i++) { bool active = int.Parse(info.transform.Find("HP").GetChild(i).name) <= hostage.hp; info.transform.Find("HP").GetChild(i).gameObject.SetActive(active); } info.gameObject.SetActive(true); }
private void OnCollisionEnter2D(Collision2D col) { Hostage hostage = col.collider.GetComponent <Hostage>(); if (hostage != null) { hostage.bulletSpeed = bulletSpeed; hostage.shootInterval = shootInterval; hostage.bullet = bullet; hostage.ammo += ammo; hostage.transform.localScale *= 1.5f; thing.Die(); source.PlayOneShot(sound); source.PlayOneShot(spawnSound); GameObject part1 = Instantiate(particle, transform.position, Quaternion.identity); Destroy(part1, 1.5f); } }
IEnumerator SpawnHostage(Hostage hostage) { yield return(new WaitForSeconds(spawnTime)); GameObject obj = Instantiate(hostagePrefab); //Setup object obj.name = hostage.name; obj.transform.position = this.transform.position; obj.GetComponent <HostageManager>().hostage = hostage; obj.GetComponent <SpringJoint2D>().distance = 0.25f; obj.GetComponent <SpringJoint2D>().connectedAnchor = transform.position; Physics2D.IgnoreCollision(this.GetComponent <Collider2D>(), obj.GetComponent <Collider2D>()); //Manage logic variables hasHostage = true; loadingHostage = false; }
/// <summary> /// 初始化:随机生成一批灰球和黑球 /// TODO:生成的位置随机性不够 /// </summary> private void InitializeBalls() { //生成一堆灰球黑球 RaycastHit hit; int range = 5; //UnityEngine.Debug.LogFormat("灰{0},黑{1}", greyNum, blackNum); for (int i = 0; i < newGreyNum; i++) { Vector3 pos = new Vector3(Random.Range(-1f, 1f), 0, Random.Range(-1f, 1f)).normalized *Random.Range(rangeMin + range, rangeMax - range); pos = new Vector3(pos.x, 0.5f, pos.z); // Vector3 dir = new Vector3(Random.Range(-1f, 1f), 0, Random.Range(-1f, 1f)).normalized * (Random.Range(rangeMin+ range, rangeMax- range) + range); Vector3 dir = new Vector3(pos.x, 0, pos.z).normalized *Random.Range(rangeMax - range, rangeMax); if (Physics.Raycast(pos, dir, out hit, 40, 1 << 10)) { // UnityEngine.Debug.Log("射中"); Hostage.GenerateSelf(hit.point - dir.normalized * greyBallR); } else { Hostage.GenerateSelf(pos + dir); // UnityEngine. Debug.LogFormat("未射中,{0},{1},{2}", pos , dir,pos+dir); } } for (int i = 0; i < newBlackNum; i++) { Vector3 pos = new Vector3(Random.Range(-1f, 1f), 0, Random.Range(-1f, 1f)).normalized *Random.Range(rangeMin + range, rangeMax - range); pos = new Vector3(pos.x, 0.5f, pos.z); // Vector3 dir = new Vector3(Random.Range(-1f, 1f), 0, Random.Range(-1f, 1f)).normalized * (Random.Range(rangeMin+ range, rangeMax- range) + range); Vector3 dir = new Vector3(pos.x, 0, pos.z).normalized *Random.Range(rangeMax - range, rangeMax); if (Physics.Raycast(pos, dir, out hit, 40, 1 << 10)) { // Debug.Log("射中"); Enemy.GenerateSelf(hit.point - dir.normalized * blackBallR); } else { Enemy.GenerateSelf(pos + dir); // Debug.LogFormat("未射中,{0}",pos + dir); } } }
void OnTriggerStay2D(Collider2D other) { if (enable) { RubyController controller = other.GetComponent <RubyController>(); if (controller != null) { controller.ChangeHealth(-1); } Hostage hostage = other.GetComponent <Hostage>(); if (hostage != null) { hostage.ChangeHealth(-1); } } }
private void Awake() { Friend.redBalls.Clear(); Hostage.greyBalls.Clear(); Enemy.blackBalls.Clear(); Friend.ClaerPool(); Hostage.ClaerPool(); Enemy.ClaerPool(); Time.timeScale = 0; Reference data = WebAPI.callback; newGreyNum = data.gm_GreyNum; newBlackNum = data.gm_BlackNum; angle1 = data.gm_Angle1; angle2 = data.gm_Angle2; angle3 = data.gm_Angle3; unionTime = data.gm_UnionTime; fadedMusicTime = data.gm_FadedMusicTime; }
private void OnTriggerEnter2D(Collider2D collision) { bool hit = false; RubyController t = collision.GetComponent <RubyController>(); if (t != null) { t.ChangeHealth(-1); hit = true; } Hostage h = collision.GetComponent <Hostage>(); if (h != null) { h.ChangeHealth(-1); hit = true; } if (hit) { Destroy(gameObject); } }
// Use this for initialization void Start() { Collectables.LoadCollectables(); nextHostage = Collectables.GrabAHostage(true); }
public void LoadHostage() { currentHostage = nextHostage; nextHostage = Collectables.GrabAHostage(true); }
private void Update() { mouseDir = (mousePos - rigidbody2d.position).normalized; float horizontal = Input.GetAxis("Horizontal"); float vertical = Input.GetAxis("Vertical"); moveDir = new Vector2(horizontal, vertical).normalized; if (Input.GetKeyDown(KeyCode.Space) && !isDashing && moveDir != Vector2.zero && dashCdTimer <= 0) { dashCdTimer = cooldownDash; isDashing = true; lastAfterImageTime = 0; } if (attackTime > 0) { attackTime -= Time.deltaTime; } if (launchCdTimer > 0) { launchCdTimer -= Time.deltaTime; } if (dashCdTimer > 0) { dashCdTimer -= Time.deltaTime; } Stab(); if (Input.GetButtonDown("Fire1") && launchCdTimer <= 0) { launchCdTimer = cooldownLaunch; Launch(); } else if (Input.GetButton("Fire2") && attackTime <= 0) { if (!Mathf.Approximately(mouseDir.x, 0.0f) || !Mathf.Approximately(mouseDir.y, 0.0f)) { lookDirection.Set(mouseDir.x, mouseDir.y); lookDirection.Normalize(); } attackTime = startTimeAttack; animator.SetTrigger("Launch"); stabPos = mousePos; stabDir = mouseDir; } if (Input.GetKeyDown(KeyCode.X)) { RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC")); if (hit.collider != null) { NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>(); if (character != null) { character.DisplayDialog(); } Hostage hostage = hit.collider.GetComponent <Hostage>(); if (hostage != null) { if (hostage.target == null) { hostage.SetDestination(transform); } else { hostage.Heal(this); } } } } if (isDashing && Time.time > lastAfterImageTime + dashAfterImageTimeInterval) { lastAfterImageTime = Time.time; GameObject afterImage = AfterImagePool.Instance.GetFromPool(); afterImage.GetComponent <PlayerDashAfterImage>().Player = gameObject; } }
void Red2Grey() { DestroySelf(); Hostage.GenerateSelf(transform.position); }
void Update() { if (health <= 0 && !dead) { dead = true; if (!GameController.instance.won) { GameController.instance.gameOver = true; } Camera.main.transform.position = transform.position; Camera.main.transform.rotation = transform.rotation; Camera.main.transform.Rotate(new Vector3(-15, 0, 85)); foreach (PlayerGun weapon in weapons) { if (weapon && weapon.gameObject.activeInHierarchy) { weapon.deadState(); } } if (crosshair) { crosshair.enabled = false; } Cursor.lockState = CursorLockMode.None; } grounded = Physics.CheckSphere(transform.position, 0.4f, groundLayer); if (grounded && velocity.y < 0) { velocity.y = -2; } if (!dead && !GameController.instance.gameOver && !GameController.instance.won) { float moveHorizontal = Input.GetAxisRaw("Horizontal"); float moveVertical = Input.GetAxisRaw("Vertical"); movement = transform.right * moveHorizontal + transform.forward * moveVertical; float speed; if (!crouching) { if (!running) { speed = walkSpeed; } else { speed = runSpeed; } } else { speed = crouchSpeed; } characterController.Move(movement.normalized * speed * Time.deltaTime); Ray ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward); if (Physics.Raycast(ray, out RaycastHit hit, 2) && hit.collider.GetComponent <Hostage>() && !hit.collider.GetComponent <Hostage>().rescued) { currentHostage = hit.collider.GetComponent <Hostage>(); rescueText.enabled = true; } else { currentHostage = null; rescueText.enabled = false; } }