void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "EnemySword" && !other.transform.root.GetComponent <HitCollider>().m_hasDealtDamage) { if (isLocalPlayer) { CharacterMovement hitMovement = other.transform.root.GetComponent <CharacterMovement>(); if (hitMovement != null) { if (m_animController.GetBool("isBlocking")) { m_audSync.PlaySound(3); m_characterScript.m_numOfBlockedAttacks++; m_animController.SetBool("blockedAttack", true); } if (m_characterScript.m_numOfBlockedAttacks > 3) { m_animController.SetBool("blockedAttack", true); m_animController.SetBool("isBlocking", false); m_characterScript.m_numOfBlockedAttacks = 0; } if (!m_animController.GetBool("isBlocking")) { HurtSound(); m_healthScript.TakeDamage(m_damage); m_characterScript.m_numOfBlockedAttacks = 0; } other.transform.root.GetComponent <HitCollider>().m_hasDealtDamage = true; } } } }
void Shoot() { nowAmmo--; if (nowAmmo <= 0) { Reload(); } ShowAmmoText(); audioSync.PlaySound(audioClipIndex); if (Physics.Raycast(cameraTransform.TransformPoint(0, 0, 0.5f), cameraTransform.forward, out hit, range)) { if (hit.transform.tag == "Player") { scoreScript.score += 30; CreateBlood(); string uIdentity = hit.transform.name; CmdTellServerWhoWasShoot(uIdentity, damage); } else if (hit.transform.tag == "Zombie") { scoreScript.score += 10; CreateBlood(); string uIdentity = hit.transform.name; CmdTellServerWhichZombieWasShoot(uIdentity, damage); } //CreateShootLine(gunPointTransform.position, Quaternion.LookRotation(hit.point - gunPointTransform.position)); } }
public void CmdDamage(int damageAmount) { if (isServer) { enemyHealth -= damageAmount; // Set under attack flag to true for state switch controller.underAttack = true; // If AI has no target set nearest player as target if (controller.target == null) { CmdSetTargetNearestPlayer(); } if (enemyHealth <= 0) { audioSync.PlaySound(this.gameObject, 2); isDead = true; } if (!isDead) { RpcSyncHealth(enemyHealth); } } }
void CheckIfTargetRange() { if (targetScript.targetTransform != null) { mouthPosition = myTransform.position + new Vector3(0, 1, 0); currentDistance = Vector3.Distance(targetScript.targetTransform.position, mouthPosition); if (currentDistance < minDistance && Time.time > nextAttack) { audioSync.PlaySound(-1); nextAttack = Time.time + attackRate; targetScript.targetTransform.GetComponent <Player_Health>().DeductHealth(damage); StartCoroutine(ChangeZombieMat()); //为主机玩家 RpcChangeZombieApperarance(); } } }
private void Update() { if (isLocalPlayer && Input.GetMouseButtonDown(0)) { Vector3 mouseDir = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position; mouseDir.z = 0; mouseDir = mouseDir.normalized; audioSync.PlaySound(0); CmdShoot(mouseDir); } }
void CmdFire() { // Create the Bullet from the Bullet Prefab var bullet = (GameObject)Instantiate( bulletPrefab, bulletSpawn.position, bulletSpawn.rotation); // Add velocity to the bullet bullet.GetComponent <Rigidbody2D>().velocity = bullet.transform.up * bulletSpeed; NetworkServer.Spawn(bullet); audioSync.PlaySound(0); // GetComponent<AudioSource>().Play(0); Debug.Log("Bullet shot"); // Destroy the bullet after 2 seconds //Destroy(bullet, 2.0f); }
void Rpc_Move(GameObject player, GameObject target) { //Calculate push vector targetDir = target.transform.position - this.transform.position; float step = rotationSpeed * Time.deltaTime; //Rotate towards a goal Vector3 newDir = Vector3.RotateTowards(transform.forward, targetDir, step, 0.0F); transform.rotation = Quaternion.LookRotation(newDir); //Set animation, sound and deactivate button // kickEffect.Play(); animator.SetTrigger("TriggerAnger"); audioSync.PlaySound(3); pushed = false; GameObject.FindGameObjectWithTag("Kick").GetComponent <Image>().color = Color.white; /* * foreach (GameObject p in GameObject.FindGameObjectsWithTag("Player")) * { * if (p.GetComponent<Behaviour>().enabled) * p.GetComponent<Behaviour>().ListenerActionAvatar("Kick", player, target); * } */ gameObject.GetComponent <UseTeleport>().NotifyBots("Kick", player, target); //Log about kick Debug.Log(GameObject.FindGameObjectWithTag("MainCamera").GetComponent <DigitalClock>().sessionID + "," + this.gameObject.GetComponent <UseTeleport>().playerID + "," + "Kick" + "," + this.name + "," + this.gameObject.transform.position + "," + player.name); //Set velocity for target's navmeshAgent player.GetComponent <UnityEngine.AI.NavMeshAgent>().ResetPath(); player.GetComponent <UnityEngine.AI.NavMeshAgent>().velocity = transform.forward * 15; }
private void PistolSound() { audioSync.PlaySound(0); }
public void CmdPlayZombieSound(int clipPosition) { audioSync.PlaySound(clipPosition); }
void CmdCallAudioSync() { audioSync.PlaySound(0, gameObject.name); }
void FixedUpdate() { //Control only by local player if (!isLocalPlayer) { return; } if (Input.GetMouseButtonUp(0)) { mLock = false; } //if left clicked if (!mLock && Input.GetMouseButtonDown(0)) { mLock = true; //Clicked place RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100)) { //if clicked on a ground or one of the teleports if (hit.transform.CompareTag("Ground") || hit.transform.CompareTag("Platform_1") || hit.transform.CompareTag("Platform_2")) { //Log movement information Debug.Log(GameObject.FindGameObjectWithTag("MainCamera").GetComponent <DigitalClock>().sessionID + "," + this.gameObject.GetComponent <UseTeleport>().playerID + "," + "moved" + "," + this.name + "," + hit.point, gameObject); //Set destination for agent navmeshAgent.destination = hit.point; } //if greetButton active and clicked on a player if (sayHelpMe && hit.transform.CompareTag("Player") && hit.transform.gameObject != gameObject) { //Calculate vector3 to a clicked player Vector3 newDir = Vector3.RotateTowards(transform.forward, hit.transform.position - this.transform.position , 1000 * Time.deltaTime, 0.0F); //Rotate player transform.rotation = Quaternion.LookRotation(newDir); //Trigger animation animator.SetTrigger("SayHello"); //Wait time before spawning light effect //StartCoroutine (WaitBeforeLightning ()); //Flicker effect to a server and clients CmdFlickerLight("ASK"); //Bunch of ifs to control who and how greet if (hit.transform.name == "PlayerMod_A(Clone)" && this.name != "PlayerMod_A(Clone)") { audioSync.PlaySound(0); Debug.Log(GameObject.FindGameObjectWithTag("MainCamera").GetComponent <DigitalClock>().sessionID + "," + this.gameObject.GetComponent <UseTeleport>().playerID + "," + "ASK" + "," + this.name + "," + hit.transform.position + "," + hit.transform.name); //hello for an AI to recognize players greet Cmd_Hello(this.gameObject, hit.transform.gameObject); } else if (hit.transform.name == "PlayerMod_B(Clone)" && this.name != "PlayerMod_B(Clone)") { audioSync.PlaySound(1); Debug.Log(GameObject.FindGameObjectWithTag("MainCamera").GetComponent <DigitalClock>().sessionID + "," + this.gameObject.GetComponent <UseTeleport>().playerID + "," + "ASK" + "," + this.name + "," + hit.transform.position + "," + hit.transform.name); //hello for an AI to recognize players greet Cmd_Hello(this.gameObject, hit.transform.gameObject); } else if (hit.transform.name == "PlayerMod_C(Clone)" && this.name != "PlayerMod_C(Clone)") { audioSync.PlaySound(2); Debug.Log(GameObject.FindGameObjectWithTag("MainCamera").GetComponent <DigitalClock>().sessionID + "," + this.gameObject.GetComponent <UseTeleport>().playerID + "," + "ASK" + "," + this.name + "," + hit.transform.position + "," + hit.transform.name); //hello for an AI to recognize players greet Cmd_Hello(this.gameObject, hit.transform.gameObject); } else if (hit.transform.name == "PlayerMod_D(Clone)" && this.name != "PlayerMod_D(Clone)") { audioSync.PlaySound(13); Debug.Log(GameObject.FindGameObjectWithTag("MainCamera").GetComponent <DigitalClock>().sessionID + "," + this.gameObject.GetComponent <UseTeleport>().playerID + "," + "ASK" + "," + this.name + "," + hit.transform.position + "," + hit.transform.name); //hello for an AI to recognize players greet Cmd_Hello(this.gameObject, hit.transform.gameObject); } //Toggle button to inactive state sayHelpMe = false; GameObject.FindGameObjectWithTag("Greet").GetComponent <Image>().color = Color.white; } else //if greetButton active and clicked on a player if (sayThank && hit.transform.CompareTag("Player") && hit.transform.gameObject != gameObject) { //Calculate vector3 to a clicked player Vector3 newDir = Vector3.RotateTowards(transform.forward, hit.transform.position - this.transform.position , 1000 * Time.deltaTime, 0.0F); //Rotate player transform.rotation = Quaternion.LookRotation(newDir); //Trigger animation animator.SetTrigger("SayHello"); //Wait time before spawning light effect //StartCoroutine (WaitBeforeLightning ()); //Flicker effect to a server and clients CmdFlickerLight("THANK"); //Bunch of ifs to control who and how greet if (hit.transform.name == "PlayerMod_A(Clone)" && this.name != "PlayerMod_A(Clone)") { audioSync.PlaySound(8); Debug.Log(GameObject.FindGameObjectWithTag("MainCamera").GetComponent <DigitalClock>().sessionID + "," + this.gameObject.GetComponent <UseTeleport>().playerID + "," + "THANK" + "," + this.name + "," + hit.transform.position + "," + hit.transform.name); //hello for an AI to recognize players greet Cmd_Hello(this.gameObject, hit.transform.gameObject); } else if (hit.transform.name == "PlayerMod_B(Clone)" && this.name != "PlayerMod_B(Clone)") { audioSync.PlaySound(9); Debug.Log(GameObject.FindGameObjectWithTag("MainCamera").GetComponent <DigitalClock>().sessionID + "," + this.gameObject.GetComponent <UseTeleport>().playerID + "," + "THANK" + "," + this.name + "," + hit.transform.position + "," + hit.transform.name); //hello for an AI to recognize players greet Cmd_Hello(this.gameObject, hit.transform.gameObject); } else if (hit.transform.name == "PlayerMod_C(Clone)" && this.name != "PlayerMod_C(Clone)") { audioSync.PlaySound(10); Debug.Log(GameObject.FindGameObjectWithTag("MainCamera").GetComponent <DigitalClock>().sessionID + "," + this.gameObject.GetComponent <UseTeleport>().playerID + "," + "THANK" + "," + this.name + "," + hit.transform.position + "," + hit.transform.name); //hello for an AI to recognize players greet Cmd_Hello(this.gameObject, hit.transform.gameObject); } else if (hit.transform.name == "PlayerMod_D(Clone)" && this.name != "PlayerMod_D(Clone)") { audioSync.PlaySound(14); Debug.Log(GameObject.FindGameObjectWithTag("MainCamera").GetComponent <DigitalClock>().sessionID + "," + this.gameObject.GetComponent <UseTeleport>().playerID + "," + "THANK" + "," + this.name + "," + hit.transform.position + "," + hit.transform.name); //hello for an AI to recognize players greet Cmd_Hello(this.gameObject, hit.transform.gameObject); } //Toggle button to inactive state sayThank = false; GameObject.FindGameObjectWithTag("ThankButton").GetComponent <Image>().color = Color.white; } } } }
public void Interacting() { if (DestroyOrLoot == 0) { audioSync.PlaySound(this.gameObject, 1); switch (ResourceType) { case 0: // wood PlayerDestroyingOrLooting.GetComponent <PlayerStats>().WoodInInventory = PlayerDestroyingOrLooting.GetComponent <PlayerStats>().WoodInInventory + AmountOfResourceToDrop; PlayerDestroyingOrLooting.GetComponent <PlayerStats>().WoodText.text = "" + PlayerDestroyingOrLooting.GetComponent <PlayerStats>().WoodInInventory; PlayerDestroyingOrLooting.GetComponent <PlayerStats>().WoodTextBackground.text = "" + PlayerDestroyingOrLooting.GetComponent <PlayerStats>().WoodInInventory; PlayerDestroyingOrLooting.GetComponent <PlayerController>().CmdDestroyResource(); break; case 1: //stone PlayerDestroyingOrLooting.GetComponent <PlayerStats>().StoneInInventory = PlayerDestroyingOrLooting.GetComponent <PlayerStats>().StoneInInventory + AmountOfResourceToDrop; PlayerDestroyingOrLooting.GetComponent <PlayerStats>().StoneText.text = "" + PlayerDestroyingOrLooting.GetComponent <PlayerStats>().StoneInInventory; PlayerDestroyingOrLooting.GetComponent <PlayerStats>().StoneTextBackground.text = "" + PlayerDestroyingOrLooting.GetComponent <PlayerStats>().StoneInInventory; PlayerDestroyingOrLooting.GetComponent <PlayerController>().CmdDestroyResource(); break; case 2: //metal PlayerDestroyingOrLooting.GetComponent <PlayerStats>().MetalInInventory = PlayerDestroyingOrLooting.GetComponent <PlayerStats>().MetalInInventory + AmountOfResourceToDrop; PlayerDestroyingOrLooting.GetComponent <PlayerStats>().MetalText.text = "" + PlayerDestroyingOrLooting.GetComponent <PlayerStats>().MetalInInventory; PlayerDestroyingOrLooting.GetComponent <PlayerStats>().MetalTextBackground.text = "" + PlayerDestroyingOrLooting.GetComponent <PlayerStats>().MetalInInventory; PlayerDestroyingOrLooting.GetComponent <PlayerController>().CmdDestroyResource(); break; } } else if (DestroyOrLoot == 1) { audioSync.PlaySound(this.gameObject, 0); switch (AmmoType) { case 0: //pistol PlayerDestroyingOrLooting.GetComponent <PlayerStats>().pistolAmmo = PlayerDestroyingOrLooting.GetComponent <PlayerStats>().pistolAmmo + AmountOfAmmoToDrop; // give PlayerDestroyingOrLooting.GetComponent <PlayerController>().CmdDestroyResource(); break; case 1: //rifle PlayerDestroyingOrLooting.GetComponent <PlayerStats>().rifleAmmo = PlayerDestroyingOrLooting.GetComponent <PlayerStats>().rifleAmmo + AmountOfAmmoToDrop; PlayerDestroyingOrLooting.GetComponent <PlayerController>().CmdDestroyResource(); break; case 2: // shotgun PlayerDestroyingOrLooting.GetComponent <PlayerStats>().shotgunAmmo = PlayerDestroyingOrLooting.GetComponent <PlayerStats>().shotgunAmmo + AmountOfAmmoToDrop; PlayerDestroyingOrLooting.GetComponent <PlayerController>().CmdDestroyResource(); break; case 3: //sniper PlayerDestroyingOrLooting.GetComponent <PlayerStats>().sniperAmmo = PlayerDestroyingOrLooting.GetComponent <PlayerStats>().sniperAmmo + AmountOfAmmoToDrop; PlayerDestroyingOrLooting.GetComponent <PlayerController>().CmdDestroyResource(); break; case 4: //rocket launcher PlayerDestroyingOrLooting.GetComponent <PlayerStats>().rocketAmmo = PlayerDestroyingOrLooting.GetComponent <PlayerStats>().rocketAmmo + AmountOfAmmoToDrop; PlayerDestroyingOrLooting.GetComponent <PlayerController>().CmdDestroyResource(); break; } } }
/// <summary> /// Method to activate /// </summary> /// <param name="target"></param> /// <param name="whatToSay">true = ask, false = thank</param> private void SaySomething(GameObject target, bool whatToSay) { //Calculate vector3 to a clicked player Vector3 newDir = Vector3.RotateTowards(transform.forward, target.transform.position - transform.position , 1000 * Time.deltaTime, 0.0F); //Rotate player transform.rotation = Quaternion.LookRotation(newDir); //Trigger animation animator.SetTrigger("SayHello"); //Flicker effect to a server and clients if (whatToSay) { CmdFlickerLight("ASK"); } else { CmdFlickerLight("THANK"); } //Bunch of ifs to control who and how greet if (target.transform.name == "PlayerMod_A(Clone)" && this.name != "PlayerMod_A(Clone)") { if (whatToSay) { audioSync.PlaySound(0); } else { audioSync.PlaySound(10); } } else if (target.transform.name == "PlayerMod_B(Clone)" && this.name != "PlayerMod_B(Clone)") { if (whatToSay) { audioSync.PlaySound(1); } else { audioSync.PlaySound(11); } } else if (target.transform.name == "PlayerMod_C(Clone)" && this.name != "PlayerMod_C(Clone)") { if (whatToSay) { audioSync.PlaySound(2); } else { audioSync.PlaySound(12); } } else if (target.transform.name == "PlayerMod_D(Clone)" && this.name != "PlayerMod_D(Clone)") { if (whatToSay) { audioSync.PlaySound(3); } else { audioSync.PlaySound(13); } } if (whatToSay) { Logger.LogAction("Ask", gameObject, target); if (GetComponent <PlayerInfo>().IsTrueLocalPlayer()) { //Toggle button to inactive state sayHelpMe = false; GameObject.FindGameObjectWithTag("Greet").GetComponent <Image>().color = Color.white; } } else { Logger.LogAction("Thank", gameObject, target); if (GetComponent <PlayerInfo>().IsTrueLocalPlayer()) { //Toggle button to inactive state sayThank = false; GameObject.FindGameObjectWithTag("ThankButton").GetComponent <Image>().color = Color.white; } } Cmd_Hello(gameObject, target); }