public void SpawnPlayerDroppedItem(Item item, int quantity, MoleController playerController) { GamePosition spawnPosition = playerController.gamePos.add(DirectionUtil.getDirectionUnitVector(playerController.facing) * Player.DROP_DISTANCE); spawnPosition.descend(-0.5f); SpawnItem(item, quantity, spawnPosition); }
void SpawnMole() { if(spawnPoints.Length == 0) {return;} int randomIndex = Random.Range(0, spawnPoints.Length); Vector3 spawnPos = spawnPoints[randomIndex].position; GameObject obj = GameObject.Instantiate(molePrefab); obj.transform.SetParent(spawnPoints[randomIndex]); obj.transform.localRotation = Quaternion.Euler(0f, 0f ,0f); obj.transform.localPosition = new Vector3(0f, obj.transform.localScale.y*0.5f, 0f); moles.Add(obj); Collision collider = obj.GetComponent<Collision>(); if(collider == null) {obj.AddComponent<Collision>();} collider.onEnter = (Collider col, GameObject o) => { moles.Remove(o); GameObject.Destroy(o); score++; }; MoleController controller = obj.GetComponent<MoleController>(); if(controller != null) { controller.SetOnDeath((GameObject mole) => { moles.Remove(mole); }); } }
public void userLogin(string username, GameObject player) { PlayerInfo playerInfo; if (!usernameToPlayerInfo.TryGetValue(username, out playerInfo)) { playerInfo = new PlayerInfo(new BeltInventory(10)); usernameToPlayerInfo.Add(username, playerInfo); } MoleController controller = player.GetComponent <MoleController> (); if (playerInfo.lastLogoutPos == null) { //first time logging in. spawn at default position controller.syncPos = new GamePosition(new Vector2(3.5f, 3.5f), 1).toStruct(); } else { controller.syncPos = playerInfo.lastLogoutPos.toStruct(); } Player playerplayer = player.GetComponent <Player> (); playerplayer.info = playerInfo; }
private void checkIfPickedUp() { if (!isServer) { return; } GameObject[] players = GameObject.FindGameObjectsWithTag("Player"); foreach (GameObject player in players) { MoleController playerController = player.GetComponent <MoleController> (); if (playerController == null || playerController.gamePos == null) { continue; } float heightDiff = Mathf.Abs(gamePos.depth - playerController.gamePos.depth); float planeDiff = (gamePos.planePosition - playerController.gamePos.planePosition).magnitude; if (heightDiff < HEIGHT_CUTOFF && planeDiff < PICK_UP_DISTANCE) { Player p = player.GetComponent <Player> (); Debug.Log(getItem() + " getting picked up of quantity " + quantity); InventoryOperation invOp = new InventoryOperation(InventoryOperation.Operation.AddItems, new byte[][] { itemData.data, System.Text.Encoding.Default.GetBytes(quantity.ToString()) }); int remainder = player.GetComponent <Player> ().PerformInventoryAction(invOp, "general"); Debug.Log("remainder: " + remainder); if (remainder >= quantity) { return; } quantity = remainder; if (!player.GetComponent <NetworkIdentity> ().isLocalPlayer) { //player.GetComponent<Player> ().beltUI.updateUI (); //} else { NetworkWriter writer = new NetworkWriter(); invOp.Serialize(writer); p.TargetPerformInventoryAction(player.GetComponent <NetworkIdentity> ().connectionToClient, writer.AsArray(), "general"); //p.TargetPickUpItem (player.GetComponent<NetworkIdentity> ().connectionToClient, getItem().Encode ()); } if (quantity <= 0) { NetworkServer.Destroy(gameObject); } } } }
private void Awake() { if (Instance == null) { Instance = this; } else { Destroy(gameObject); } }
private void SpawnMole() { if (!hasMole) { int num = CalculateRarity(); GameObject mole = Instantiate(moles[num], transform.position, Quaternion.identity) as GameObject; MoleController moleController = mole.GetComponent <MoleController>(); moleController.parent = this.gameObject; //multiplies the score of each mole in the next level moleController.score = moleController.score * TimeController.currentLevel; hasMole = true; } Invoke("SpawnMole", Random.Range(3f, 7f)); }
/// <summary> /// もぐらタップ検知処理 /// </summary> private void DetectionMoleTap() { if (!TryGetTouchPosition(out Vector2 touchPosition)) { return; } // タップ対象を全て取得 Ray ray = Camera.main.ScreenPointToRay(touchPosition); RaycastHit[] hitList = Physics.RaycastAll(ray); if (hitList == null) { return; } // モグラかマジロがタップされた場合 foreach (RaycastHit hit in hitList) { // モグラ類のみが対象 MoleController mc = hit.transform.root.gameObject.GetComponent <MoleController>(); if (mc == null || mc.delete) { continue; } // ヒット・スコア加算処理 switch (mc.kind) { case MoleController.KIND.MOLE: mc.Hit(); AddScore(moleScore); break; case MoleController.KIND.MOLEGOLD: mc.Hit(); AddScore(molegoldScore); break; case MoleController.KIND.MAJIRO: mc.Hit(); AddScore(majiroScore); break; } } }
/// <summary> /// もぐら出現処理 /// </summary> private void GenetateMole() { // 時間をキーに変換 string key = countTime.ToString("F0"); if (!appearInfoMap.ContainsKey(key)) { return; } // もぐら出現情報Mapよりキーに紐づくBeanリストを取得 List <AppearInfoBean> appearInfoBeanList = appearInfoMap[key]; foreach (AppearInfoBean bean in appearInfoBeanList) { // Beanに設定されている回数分生成する for (int i = 0; i < bean.Count; i++) { // 種類に応じて生成 GameObject generateMole = null; switch (bean.Kind) { case GameUtil.Const.TAG_NAME_MOLE: generateMole = GenerateMoleObj(mole_PlacedPrefab); break; case GameUtil.Const.TAG_NAME_MOLEGOLD: generateMole = GenerateMoleObj(molegold_PlacedPrefab); break; case GameUtil.Const.TAG_NAME_MAJIRO: generateMole = GenerateMoleObj(majiro_PlacedPrefab); break; } // Beanからエスケープタイムとアニメーション速度を設定 MoleController mc = generateMole.GetComponent <MoleController>(); mc.animSpeed = bean.AnimSpeed; mc.hideBaseTime = bean.EscapeTime; } } // 時間に対して一度のみ生成するためキーを削除 appearInfoMap.Remove(key); }
private void Update() { if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { Instantiate(particles, hit.point, Quaternion.identity); if (hit.collider.tag == "Mole") { MoleController moleController = hit.collider.gameObject.GetComponent <MoleController>(); moleController.SetColliderOn(0); moleController.animator.SetTrigger("Hit"); } } } }
// Update is called once per frame void Update() { if (Input.touchCount > 0) { Touch touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began) { Ray ray = arCamera.ScreenPointToRay(touch.position); RaycastHit hitObject; if (Physics.Raycast(ray, out hitObject)) // true if we hit something { MoleController mole = hitObject.transform.GetComponent <MoleController>(); if (mole != null) { mole.Whack(); } } } } }
private void Awake() { moleRb = GetComponent <Rigidbody2D>(); moleAnimator = GetComponent <Animator>(); instance = this; }
private void Start() { treeAnimator = transform.parent.GetComponentInChildren <Animator>(); treeAudioSource = transform.parent.GetComponentInChildren <AudioSource>(); moleController = FindObjectOfType <MoleController>();//Singleton }