Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Yaga15 · May 11, 2020 at 08:19 AM · multiplayerplayerspawnsetactivepun

mutiplayer player clone not active

alt text

codes: Manager: [SerializeField] public class PlayerInfo {

     public ProfileData profile;
     public int actor;
     public short kills;
     public short deaths;

     public PlayerInfo (ProfileData p, int a, short k, short d)
     {
         this.profile = p;
         this.actor = a;
         this.kills = k;
         this.deaths = d;
     }
 }

 public enum GameState
 {
     Waiting = 0,
     Starting = 1,
     Playing = 2,
     Ending = 3
 }

 public class Manager : MonoBehaviourPunCallbacks, IOnEventCallback
 {
     #region Fields
     public int mainmenu = 0;
     public int killcount = 3;
     public bool perpetual = false;

     public GameObject mapcam;

     public string player_prefab_string;
     public GameObject player_prefab;
     public Transform[] spawn_points;

     public List<PlayerInfo> playerInfo = new List<PlayerInfo>();
     public int myind;

     private Text ui_mykills;
     private Text ui_mydeaths;
     private Transform ui_leaderboard;
     private Transform ui_endgame;

     private GameState state = GameState.Waiting;

     #endregion

     #region Codes

     public enum EventCodes : byte
     {
         NewPlayer,
         UpdatePlayers,
         ChangeStat,
         NewMatch
     }

     #endregion

     #region MB Callbacks
     [SerializeField]
     private Karakter_multi km;
     private Scene sc;
     private GameObject seçili;
     private void Start()
     {
         
         //km = GetComponent<Karakter_multi>();
         //km = FindObjectOfType<Karakter_multi>();
         sc = SceneManager.GetSceneByName("Multi_Select");
         km = GameObject.FindObjectOfType<Karakter_multi>();
         //km = GameObject.FindGameObjectWithTag("Deneme").GetComponent<Karakter_multi>();
         player_prefab_string = km.isim;
         player_prefab = km.seçili;
         mapcam.SetActive(false);
         
         ValidateConnection();
         InitializeUI();
         NewPlayer_S(Launcher.myProfile);
         Spawn();
     }

     private void Update()
     {
        

         if (state == GameState.Ending)
         {
             return;
         }

         if (Input.GetKeyDown(KeyCode.Tab))
         {
             if (ui_leaderboard.gameObject.activeSelf) ui_leaderboard.gameObject.SetActive(false);
             else Leaderboard(ui_leaderboard);
         }
     }

     private void OnEnable()
     {
         PhotonNetwork.AddCallbackTarget(this);
     }
     private void OnDisable()
     {
         PhotonNetwork.RemoveCallbackTarget(this);
     }

     #endregion

     #region Photon

     public void OnEvent (EventData photonEvent)
     {
         if (photonEvent.Code >= 200) return;

         EventCodes e = (EventCodes) photonEvent.Code;
         object[] o = (object[]) photonEvent.CustomData;

         switch (e)
         {
             case EventCodes.NewPlayer:
                 NewPlayer_R(o);
                 break;

             case EventCodes.UpdatePlayers:
                 UpdatePlayers_R(o);
                 break;

             case EventCodes.ChangeStat:
                 ChangeStat_R(o);
                 break;

             case EventCodes.NewMatch:
                 NewMatch_R();
                 break;
         }
     }

     public override void OnLeftRoom ()
     {
         base.OnLeftRoom();
         SceneManager.LoadScene(mainmenu);
     }

     #endregion

     #region Methods

     public void Spawn ()
     {
         Transform t_spawn = spawn_points[Random.Range(0, spawn_points.Length)];

         if (PhotonNetwork.IsConnected)
         {
             PhotonNetwork.Instantiate(player_prefab_string, t_spawn.position, t_spawn.rotation);
         }

         else
         {
             Debug.Log("WORKING");
             GameObject newPlayer = Instantiate(player_prefab, t_spawn.position, t_spawn.rotation) as GameObject;
         }
     }

     private void InitializeUI ()
     {
         ui_mykills = GameObject.Find("HUD/Stats/Kills/Text").GetComponent<Text>();
         ui_mydeaths = GameObject.Find("HUD/Stats/Deaths/Text").GetComponent<Text>();
         ui_leaderboard = GameObject.Find("HUD").transform.Find("Leaderboard").transform;
         ui_endgame = GameObject.Find("Canvas").transform.Find("End Game").transform;

         RefreshMyStats();
     }

     private void RefreshMyStats ()
     {
         if (playerInfo.Count > myind)
         {
             ui_mykills.text = $"{playerInfo[myind].kills} kills";
             ui_mydeaths.text = $"{playerInfo[myind].deaths} deaths";
         }
         else
         {
             ui_mykills.text = "0 kills";
             ui_mydeaths.text = "0 deaths";
         }
     }

     private void Leaderboard (Transform p_lb)
     {
         // clean up
         for (int i = 2; i < p_lb.childCount; i++)
         {
             Destroy(p_lb.GetChild(i).gameObject);
         }

         // set details
         p_lb.Find("Header/Mode").GetComponent<Text>().text = "FREE FOR ALL";
         p_lb.Find("Header/Map").GetComponent<Text>().text = "Battlefield";

         // cache prefab
         GameObject playercard = p_lb.GetChild(1).gameObject;
         playercard.SetActive(false);

         // sort
         List<PlayerInfo> sorted = SortPlayers(playerInfo);

         // display
         bool t_alternateColors = false;
         foreach (PlayerInfo a in sorted)
         {
             GameObject newcard = Instantiate(playercard, p_lb) as GameObject;

             if (t_alternateColors) newcard.GetComponent<Image>().color = new Color32(0, 0, 0, 180);
             t_alternateColors = !t_alternateColors;

             newcard.transform.Find("Level").GetComponent<Text>().text = a.profile.level.ToString("00");
             newcard.transform.Find("Username").GetComponent<Text>().text = a.profile.username;
             newcard.transform.Find("Score Value").GetComponent<Text>().text = (a.kills * 100).ToString();
             newcard.transform.Find("Kills Value").GetComponent<Text>().text = a.kills.ToString();
             newcard.transform.Find("Deaths Value").GetComponent<Text>().text = a.deaths.ToString();

             newcard.SetActive(true);
         }

         // activate
         p_lb.gameObject.SetActive(true);
     }

     private List<PlayerInfo> SortPlayers (List<PlayerInfo> p_info)
     {
         List<PlayerInfo> sorted = new List<PlayerInfo>();

         while (sorted.Count < p_info.Count)
         {
             // set defaults
             short highest = -1;
             PlayerInfo selection = p_info[0];

             // grab next highest player
             foreach (PlayerInfo a in p_info)
             {
                 if (sorted.Contains(a)) continue;
                 if (a.kills > highest)
                 {
                     selection = a;
                     highest = a.kills;
                 }
             }

             // add player
             sorted.Add(selection);
         }

         return sorted;
     }

     private void ValidateConnection ()
     {
         if (PhotonNetwork.IsConnected) return;
         SceneManager.LoadScene(mainmenu);
     }

     private void StateCheck ()
     {
         if (state == GameState.Ending)
         {
             EndGame();
         }
     }

     private void ScoreCheck ()
     {
         // define temporary variables
         bool detectwin = false;

         // check to see if any player has met the win conditions
         foreach (PlayerInfo a in playerInfo)
         {
             // free for all
             if(a.kills >= killcount)
             {
                 detectwin = true;
                 break;
             }
         }

         // did we find a winner?
         if (detectwin)
         {
             // are we the master client? is the game still going?
             if (PhotonNetwork.IsMasterClient && state != GameState.Ending)
             {
                 // if so, tell the other players that a winner has been detected
                 UpdatePlayers_S((int)GameState.Ending, playerInfo);
             }
         }
     }

     private void EndGame()
     {
         // set game state to ending
         state = GameState.Ending;

         // disable room
         if (PhotonNetwork.IsMasterClient)
         {
             PhotonNetwork.DestroyAll();

             if (!perpetual)
             {
                 PhotonNetwork.CurrentRoom.IsVisible = false;
                 PhotonNetwork.CurrentRoom.IsOpen = false;
             }
         }

         // activate map camera
         mapcam.SetActive(true);

         // show end game ui
         ui_endgame.gameObject.SetActive(true);
         Leaderboard(ui_endgame.Find("Leaderboard"));

         // wait X seconds and then return to main menu
         StartCoroutine(End(6f));
     }

     #endregion

     #region Events

     public void NewPlayer_S (ProfileData p)
     {
         object[] package = new object[6];

         package[0] = p.username;
         package[1] = p.level;
         package[2] = p.xp;
         package[3] = PhotonNetwork.LocalPlayer.ActorNumber;
         package[4] = (short) 0;
         package[5] = (short) 0;

         PhotonNetwork.RaiseEvent(
             (byte)EventCodes.NewPlayer,
             package,
             new RaiseEventOptions { Receivers = ReceiverGroup.MasterClient },
             new SendOptions { Reliability = true }
         );
     }
     public void NewPlayer_R (object[] data)
     {
         PlayerInfo p = new PlayerInfo(
             new ProfileData(
                 (string) data[0],
                 (int) data[1],
                 (int) data[2]
             ),
             (int) data[3],
             (short) data[4],
             (short) data[5]
         );

         playerInfo.Add(p);

         UpdatePlayers_S((int)state, playerInfo);
     }

     public void UpdatePlayers_S (int state, List<PlayerInfo> info)
     {
         object[] package = new object[info.Count + 1];

         package[0] = state;
         for (int i = 0; i < info.Count; i++)
         {
             object[] piece = new object[6];

             piece[0] = info[i].profile.username;
             piece[1] = info[i].profile.level;
             piece[2] = info[i].profile.xp;
             piece[3] = info[i].actor;
             piece[4] = info[i].kills;
             piece[5] = info[i].deaths;

             package[i + 1] = piece;
         }

         PhotonNetwork.RaiseEvent (
             (byte)EventCodes.UpdatePlayers, 
             package, 
             new RaiseEventOptions { Receivers = ReceiverGroup.All }, 
             new SendOptions { Reliability = true }
         );
     }
     public void UpdatePlayers_R (object[] data)
     {
         state = (GameState)data[0];
         playerInfo = new List<PlayerInfo>();

         for (int i = 1; i < data.Length; i++)
         {
             object[] extract = (object[]) data[i];

             PlayerInfo p = new PlayerInfo (
                 new ProfileData (
                     (string) extract[0],
                     (int) extract[1],
                     (int) extract[2]
                 ),
                 (int) extract[3],
                 (short) extract[4],
                 (short) extract[5]
             );

             playerInfo.Add(p);

             if (PhotonNetwork.LocalPlayer.ActorNumber == p.actor) myind = i - 1;
         }

         StateCheck();
     }

     public void ChangeStat_S (int actor, byte stat, byte amt)
     {
         object[] package = new object[] { actor, stat, amt };

         PhotonNetwork.RaiseEvent(
             (byte)EventCodes.ChangeStat,
             package,
             new RaiseEventOptions { Receivers = ReceiverGroup.All },
             new SendOptions { Reliability = true }
         );
     }
     public void ChangeStat_R (object[] data)
     {
         int actor = (int) data[0];
         byte stat = (byte) data[1];
         byte amt = (byte) data[2];

         for (int i = 0; i < playerInfo.Count; i++)
         {
             if(playerInfo[i].actor == actor)
             {
                 switch(stat)
                 {
                     case 0: //kills
                         playerInfo[i].kills += amt;
                         Debug.Log($"Player {playerInfo[i].profile.username} : kills = {playerInfo[i].kills}");
                         break;

                     case 1: //deaths
                         playerInfo[i].deaths += amt;
                         Debug.Log($"Player {playerInfo[i].profile.username} : deaths = {playerInfo[i].deaths}");
                         break;
                 }

                 if(i == myind) RefreshMyStats();
                 if (ui_leaderboard.gameObject.activeSelf) Leaderboard(ui_leaderboard);

                 break;
             }
         }

         ScoreCheck();
     }

     public void NewMatch_S ()
     {
         PhotonNetwork.RaiseEvent(
             (byte)EventCodes.NewMatch,
             null,
             new RaiseEventOptions { Receivers = ReceiverGroup.All },
             new SendOptions { Reliability = true }
         );
     }
     public void NewMatch_R ()
     {
         // set game state to waiting
         state = GameState.Waiting;

         // deactivate map camera
         mapcam.SetActive(false);

         // hide end game ui
         ui_endgame.gameObject.SetActive(false);

         // reset scores
         foreach (PlayerInfo p in playerInfo)
         {
             p.kills = 0;
             p.deaths = 0;
         }

         // reset ui
         RefreshMyStats();

         // spawn
         Spawn();
     }

     #endregion

     #region Coroutines

     private IEnumerator End (float p_wait)
     {
         yield return new WaitForSeconds(p_wait);

         if(perpetual)
         {
             // new match
             if(PhotonNetwork.IsMasterClient)
             {
                 NewMatch_S();
             }
         }
         else
         {
             // disconnect
             PhotonNetwork.AutomaticallySyncScene = false;
             PhotonNetwork.LeaveRoom();
         }
     }

     #endregion
 }

} Player Select: public class Karakter_multi : MonoBehaviourPunCallbacks {

     public GameObject cn;
     public string isim;
     public string arcane;
     public string ıce;
     public string flame;
     public string elec;
     public string posion;
     public string divine;
     public GameObject seçili;
     public GameObject[] Wizards;
     public GameObject[] WizardsObj;
     public int wizsayi;

     // Start is called before the first frame update
     void Start()
     {

         WizardsObj[0].SetActive(true);
         WizardsObj[1].SetActive(true);
         WizardsObj[2].SetActive(true);
         WizardsObj[3].SetActive(true);
         WizardsObj[4].SetActive(true);
         WizardsObj[5].SetActive(true);
         seçili = WizardsObj[wizsayi];
         for (int i = 0; i < Wizards.Length; i++)
         {
             Wizards[i].SetActive(false);
         }
         Wizards[wizsayi].SetActive(true);

     }
     void Update()
     {
         
         DontDestroyOnLoad(cn);
         seçili = WizardsObj[wizsayi];
     }
     public void NextButton()
     {
         wizsayi++;
         Wizards[wizsayi - 1].SetActive(false);
         if (wizsayi > Wizards.Length - 1)
         {
             wizsayi = 0;
         }
         Wizards[wizsayi].SetActive(true);
     }
     public void PreButton()
     {
         wizsayi--;
         Wizards[wizsayi + 1].SetActive(false);
         if (wizsayi < 0)
         {
             wizsayi = 5;
         }
         if (wizsayi < 0)
         {
             Wizards[5].SetActive(true);
         }
         Wizards[wizsayi].SetActive(true);
     }
     public void ArcaneWizard()
     {
         //cn.SetActive(false);
         isim = arcane;
         seçili = WizardsObj[0];
         SceneManager.LoadScene("Menu");
     }
     public void ElecWizard()
     {
         //cn.SetActive(false);
         isim = elec;
         seçili = WizardsObj[4];
         SceneManager.LoadScene("Menu");
     }
     public void DivineWizard()
     {
         //cn.SetActive(false);
         isim = divine;
         seçili = WizardsObj[5];
         SceneManager.LoadScene("Menu");
     }
     public void PosionWizard()
     {
         //cn.SetActive(false);
         isim = posion;
         seçili = WizardsObj[3];
         SceneManager.LoadScene("Menu");
     }
     public void FlameWizard()
     {
         //cn.SetActive(false);
         isim = flame;
         seçili = WizardsObj[2];
         SceneManager.LoadScene("Menu");
     }
     public void İceWizard()
     {
         //cn.SetActive(false);
         isim = ıce;
         seçili = WizardsObj[1];
         SceneManager.LoadScene("Menu");
     }
 }
 

} Player: public class multiplayerc : MonoBehaviourPunCallbacks {

public GameObject mesh;

public Transform spawnPos;

public Transform spawnPoskalkan;

public Transform spawnPosportal1;

public Transform spawnPosaura;

public GameObject sp0;

public GameObject sp1;

public GameObject sp2;

public GameObject sp3;

public GameObject sp4;

public GameObject sp5;

public GameObject sp6;

public GameObject sp7;

public GameObject sp8;

public GameObject sp9;

public int canmax=100;

private Transform ui_healthbar;

public int manamax = 100;

private Transform ui_manabar;

public float attackDamage=5;

public float attackRange=3;

public float attackCoolDown=1;

private Manager manager;

public TextMeshPro playerUsername;

private Text ui_username;

private multiplayerc pc;

private float attackTimer;

public bool lockCursor;

public float mouseSensitivity = 10;

public Vector2 pitchMinMax = new Vector2(-40, 85);

public float rotationSmoothTime = 0.1f;

[HideInInspector] public ProfileData playerProfile;

     public float speedH = 2.0f;
     public float speedV = 2.0f;

     Camera cam;
     public float yaw;
     public float pitch;
     float smoothYaw;
     float smoothPitch;

     float yawSmoothV;
     float pitchSmoothV;
     float verticalVelocity;
     Vector3 velocity;
     Vector3 smoothV;
     Vector3 rotationSmoothVelocity;
     Vector3 currentRotation;

     bool jumping;
     float lastGroundedTime;
     bool disabled;
     //public Transform spawnPos;
     //public Transform spawnPoskalkan;
     //public Transform spawnPosportal1;
     //public Transform spawnPosaura;
     //public GameObject sp0;
     //public GameObject sp1;
     //public GameObject sp2;
     //public GameObject sp3;
     //public GameObject sp4;
     //public GameObject sp5;
     //public GameObject sp6;
     //public GameObject sp7;
     //public GameObject sp8;
     //public GameObject sp9;
     //public Image gmbar;
     public Animator anim;
     public PhotonView pw;
     public float zaman = 0;
     public bool durmak = true;
     public bool saldırı = false;
     public bool hareket = false;
     public bool hızlıhareket = false;
     public float hiz = 7.5f, yercekimi = 10f, yorgunluk = 0f;
     public bool dc;
     public bool uzunsaldırı = false;
     Rigidbody rd;
     public float can = 100;
     private Text cantext;
     public float mana = 100;
     private Text manatext;

     [PunRPC]
     private void Start()
     {
         gameObject.SetActive(pw.IsMine);
         canmax = 100;
         manamax = 100;
         manager = GameObject.Find("Manager").GetComponent<Manager>();
         pc = GetComponent<multiplayerc>();
         cam = Camera.main;
         if (lockCursor)
         {
             Cursor.lockState = CursorLockMode.Locked;
             Cursor.visible = false;
         }

         

         yaw = transform.eulerAngles.y;
         //pitch = cam.transform.localEulerAngles.x;
         smoothYaw = yaw;
         smoothPitch = pitch;

         pw = GetComponent<PhotonView>();


         if (pw.IsMine == true)
         {
             pw.RPC("SyncProfile", RpcTarget.All, Launcher.myProfile.username, Launcher.myProfile.level, Launcher.myProfile.xp);
             gameObject.layer = 11;
             ChangeLayerRecursively(mesh.transform, 11);
             gameObject.tag = ("Player");
             cantext = GameObject.Find("HUD/Health/Can").GetComponent<Text>();
             manatext = GameObject.Find("HUD/Fuel/Mana").GetComponent<Text>();
             ui_healthbar = GameObject.Find("HUD/Health/Bar").transform;
             ui_manabar = GameObject.Find("HUD/Fuel/Bar").transform;
             RefreshHealthBar();
             ui_username = GameObject.Find("HUD/Username/Text").GetComponent<Text>();
             ui_username.text = Launcher.myProfile.username;
             playerUsername.text = Launcher.myProfile.username;
             uzunsaldırı = false;
             durmak = true;
             dc = true;
             hareket = false;
             saldırı = false;
             hızlıhareket = false;
             anim = GetComponent<Animator>();
             rd = GetComponent<Rigidbody>();
             //GetComponent<Renderer>().material.color = Color.red;
             //gmbar.GetComponent<Image>().color = new Color32(191, 255, 97, 100);

         }
     }
     private void ChangeLayerRecursively(Transform p_trans, int p_layer)
     {
         p_trans.gameObject.layer = p_layer;
         foreach (Transform t in p_trans) ChangeLayerRecursively(t, p_layer);
     }

     [PunRPC]
     void Update()
     {
         if (!pw.IsMine) return;
         if (pw.IsMine == true)
         {
             Multi_Update();
             RefreshHealthBar();
         }

     }
     void RefreshHealthBar()
     {
         float t_health_ratio = (float)can / (float)canmax;
         ui_healthbar.localScale = Vector3.Lerp(ui_healthbar.localScale, new Vector3(t_health_ratio, 1, 1), Time.deltaTime * 8f);
         float t_mana_ratio = (float)mana / (float)manamax;
         ui_manabar.localScale = Vector3.Lerp(ui_manabar.localScale, new Vector3(t_mana_ratio, 1, 1), Time.deltaTime * 8f);
     }
     [PunRPC]
     private void DoAttack()
     {

         Ray ray = cam.ScreenPointToRay(Input.mousePosition);
         RaycastHit t_hit;

         if (Physics.Raycast(ray, out t_hit, attackRange))
         {
             if (t_hit.collider.gameObject.layer == 11)
             {
                 //give damage
                 t_hit.collider.transform.root.gameObject.GetPhotonView().RPC("TakeDamage", RpcTarget.All, attackDamage, PhotonNetwork.LocalPlayer.ActorNumber);

                 //check for kill
                 //if (t_hit.collider.transform.root.gameObject.GetComponent<Player>().CheckKill(loadout[currentIndex].damage))
                 //{
                 //    manager.ChangeStat_S(PhotonNetwork.LocalPlayer.ActorNumber, 0, 1);
                 //}

                 //show hitmarker
                 
                 
                 attackRange = 1f;
             }
         }

     }
     public void TakeDamage(int p_damage, int p_actor)
     {
         if (pw.IsMine)
         {
             can -= p_damage;
             //RefreshHealthBar();

             if (can <= 0)
             {
                 manager.Spawn();
                 manager.ChangeStat_S(PhotonNetwork.LocalPlayer.ActorNumber, 1, 1);

                 if (p_actor >= 0)
                     manager.ChangeStat_S(p_actor, 0, 1);

                 PhotonNetwork.Destroy(gameObject);
             }
         }
     }
     [PunRPC]
     public void Multi_Update()
     {
         attackTimer += Time.deltaTime;
         if (pc.dc == true)
         {
             if (Input.GetMouseButtonUp(0) && attackTimer >= attackCoolDown)
             {
                 pc.dc = false;
                 attackTimer = 0f;
                 DoAttack();
             }
         }
         yaw += speedH * Input.GetAxis("Mouse X");
         pitch -= speedV * Input.GetAxis("Mouse Y");

         transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);


         if (disabled)
         {
             return;
         }

         Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));

         Vector3 inputDir = new Vector3(input.x, 0, input.y).normalized;
         Vector3 worldInputDir = transform.TransformDirection(inputDir);



         float mX = Input.GetAxisRaw("Mouse X");
         float mY = Input.GetAxisRaw("Mouse Y");


         float mMag = Mathf.Sqrt(mX * mX + mY * mY);
         if (mMag > 5)
         {
             mX = 0;
             mY = 0;
         }

         yaw += mX * mouseSensitivity;
         pitch -= mY * mouseSensitivity;
         pitch = Mathf.Clamp(pitch, pitchMinMax.x, pitchMinMax.y);
         smoothPitch = Mathf.SmoothDampAngle(smoothPitch, pitch, ref pitchSmoothV, rotationSmoothTime);
         smoothYaw = Mathf.SmoothDampAngle(smoothYaw, yaw, ref yawSmoothV, rotationSmoothTime);

         transform.eulerAngles = Vector3.up * smoothYaw;


         if (mana >= 10)
         {

             if (Input.GetKeyDown(KeyCode.Alpha3))
             {
                 Instantiate(sp3, spawnPos.position, spawnPos.rotation);
                 mana -= 10;
             }
             if (Input.GetKeyDown(KeyCode.Alpha4))
             {
                 Instantiate(sp4, spawnPos.position, spawnPos.rotation);
                 mana -= 10;
             }
             if (Input.GetKeyDown(KeyCode.Alpha5))
             {
                 Instantiate(sp5, spawnPos.position, spawnPos.rotation);
                 mana -= 10;
             }
             if (Input.GetKeyDown(KeyCode.Alpha6))
             {
                 Instantiate(sp6, spawnPos.position, spawnPos.rotation);
                 mana -= 10;
             }
             if (Input.GetKeyDown(KeyCode.Alpha7))
             {
                 Instantiate(sp7, spawnPos.position, spawnPos.rotation);
                 mana -= 10;
             }

             if (Input.GetKeyDown(KeyCode.Keypad3))
             {
                 Instantiate(sp3, spawnPos.position, spawnPos.rotation);
                 mana -= 10;
             }
             if (Input.GetKeyDown(KeyCode.Keypad4))
             {
                 Instantiate(sp4, spawnPos.position, spawnPos.rotation);
                 mana -= 10;
             }
             if (Input.GetKeyDown(KeyCode.Keypad5))
             {
                 Instantiate(sp5, spawnPos.position, spawnPos.rotation);
                 mana -= 10;
             }
             if (Input.GetKeyDown(KeyCode.Keypad6))
             {
                 Instantiate(sp6, spawnPos.position, spawnPos.rotation);
                 mana -= 10;
             }
             if (Input.GetKeyDown(KeyCode.Keypad7))
             {
                 Instantiate(sp7, spawnPos.position, spawnPos.rotation);
                 mana -= 10;
             }

         }
         if (zaman >= -10f)
         {
             durmak = true;
             dc = true;
             saldırı = false;
             uzunsaldırı = false;
             hareket = false;
             hızlıhareket = false;
             anim.SetBool("attack_long_001", false);
             anim.SetBool("attack_short_001", false);
             anim.SetBool("move_forward", false);
             anim.SetBool("move_forward_fast", false);
             anim.SetBool("idle_normal", true);
         }
         if (zaman <= 0)
         {
             zaman += 5f * Time.deltaTime;
         }
         if (zaman <= -25f)
         {
             zaman = -25f;
         }
         if (dc == true)
         {
             if (Input.GetMouseButtonDown(0))
             {
                 print(1);
                 zaman -= 75f * Time.deltaTime * 100f * 4f;
                 saldırı = true;
                 uzunsaldırı = false;
                 hareket = false;
                 hızlıhareket = false;
                 durmak = false;
                 anim.SetBool("attack_long_001", false);
                 anim.SetBool("attack_short_001", true);
                 anim.SetBool("move_forward", false);
                 anim.SetBool("move_forward_fast", false);
                 anim.SetBool("idle_normal", false);
             }
         }
         if (dc == true)
         {
             if (Input.GetMouseButtonDown(1))
             {
                 print(2);
                 zaman -= 75f * Time.deltaTime * 100f * 4f;
                 saldırı = false;
                 uzunsaldırı = true;
                 hareket = false;
                 hızlıhareket = false;
                 durmak = false;
                 dc = false;
                 anim.SetBool("attack_short_001", false);
                 anim.SetBool("attack_long_001", true);
                 anim.SetBool("move_forward", false);
                 anim.SetBool("move_forward_fast", false);
                 anim.SetBool("idle_normal", false);
                 //    Invoke("PlayAudioClip",1f);
             }
         }
         //if (isgrounded == true){

         if (Input.GetKey(KeyCode.Space))
         {

             transform.Translate(0, 5f * Time.deltaTime, 0);
         }
         if (Input.GetKey(KeyCode.LeftControl))
         {

             transform.Translate(0, -5f * Time.deltaTime, 0);
         }
         if (durmak == true)
         {

             yorgunluk -= 5f * Time.deltaTime;
             anim.SetBool("attack_long_001", false);
             anim.SetBool("attack_short_001", false);
             anim.SetBool("move_forward", false);
             anim.SetBool("move_forward_fast", false);
             anim.SetBool("idle_normal", true);

         }
         if (Input.GetKey(KeyCode.A))
         {
             //transform.Rotate (0, -2.5f, 0);
             zaman -= 75f * Time.deltaTime * 4f;
             anim.SetBool("attack_long_001", false);
             anim.SetBool("move_forward", true);
             anim.SetBool("idle_normal", false);
             anim.SetBool("attack_short_001", false);
             anim.SetBool("move_forward_fast", false);
             uzunsaldırı = false;
             saldırı = false;
             hareket = true;
             hızlıhareket = false;
             durmak = false;
             dc = false;
             transform.Translate(-1 * Time.deltaTime * hiz, 0, 0);
             print("at");
         }
         if (Input.GetKey(KeyCode.D))
         {
             //transform.Rotate (0, 2.5f, 0);
             zaman -= 75f * Time.deltaTime * 4f;
             anim.SetBool("move_forward", true);
             anim.SetBool("attack_long_001", false);
             anim.SetBool("idle_normal", false);
             anim.SetBool("attack_short_001", false);
             anim.SetBool("move_forward_fast", false);
             uzunsaldırı = false;
             saldırı = false;
             hareket = true;
             hızlıhareket = false;
             durmak = false;
             dc = false;
             transform.Translate(1 * Time.deltaTime * hiz, 0, 0);
             print("at");
         }
         if (Input.GetKey(KeyCode.W))
         {
             zaman -= 75f * Time.deltaTime * 4f;
             anim.SetBool("move_forward", true);
             anim.SetBool("attack_long_001", false);
             anim.SetBool("idle_normal", false);
             anim.SetBool("attack_short_001", false);
             anim.SetBool("move_forward_fast", false);
             uzunsaldırı = false;
             saldırı = false;
             hareket = true;
             hızlıhareket = false;
             durmak = false;
             dc = false;
             transform.Translate(0, 0, 1 * Time.deltaTime * hiz);
             print("at");
         }
         if (Input.GetKey(KeyCode.S))
         {
             zaman -= 75f * Time.deltaTime * 4f;
             anim.SetBool("move_forward", true);
             anim.SetBool("attack_long_001", false);
             anim.SetBool("idle_normal", false);
             anim.SetBool("attack_short_001", false);
             anim.SetBool("move_forward_fast", false);
             uzunsaldırı = false;
             saldırı = false;
             hareket = true;
             hızlıhareket = false;
             durmak = false;
             dc = false;
             transform.Translate(0, 0, -1 * Time.deltaTime * hiz);
             print("at");
         }
         if (Input.GetKey(KeyCode.RightArrow))
         {
             zaman -= 75f * Time.deltaTime * 4f;
             //transform.Rotate(0, 2.5f, 0);
             anim.SetBool("move_forward", true);
             anim.SetBool("attack_long_001", false);
             anim.SetBool("idle_normal", false);
             anim.SetBool("attack_short_001", false);
             anim.SetBool("move_forward_fast", false);
             uzunsaldırı = false;
             saldırı = false;
             hareket = true;
             hızlıhareket = false;
             durmak = false;
             dc = false;
             transform.Translate(1 * Time.deltaTime * hiz, 0, 0);
             print("at");
         }
         if (Input.GetKey(KeyCode.LeftArrow))
         {
             //transform.Rotate(0, -2.5f, 0);
             zaman -= 75f * Time.deltaTime * 4f;
             anim.SetBool("move_forward", true);
             anim.SetBool("attack_long_001", false);
             anim.SetBool("idle_normal", false);
             anim.SetBool("attack_short_001", false);
             anim.SetBool("move_forward_fast", false);
             uzunsaldırı = false;
             saldırı = false;
             hareket = true;
             hızlıhareket = false;
             durmak = false;
             dc = false;
             transform.Translate(-1 * Time.deltaTime * hiz, 0, 0);
             print("at");
         }
         if (Input.GetKey(KeyCode.UpArrow))
         {
             zaman -= 75f * Time.deltaTime * 4f;
             anim.SetBool("move_forward", true);
             anim.SetBool("attack_long_001", false);
             anim.SetBool("idle_normal", false);
             anim.SetBool("attack_short_001", false);
             anim.SetBool("move_forward_fast", false);
             uzunsaldırı = false;
             saldırı = false;
             hareket = true;
             hızlıhareket = false;
             durmak = false;
             dc = false;
             transform.Translate(0, 0, 1 * Time.deltaTime * hiz);
             print("at");
         }
         if (Input.GetKey(KeyCode.DownArrow))
         {
             zaman -= 75f * Time.deltaTime * 4f;
             anim.SetBool("move_forward", true);
             anim.SetBool("attack_long_001", false);
             anim.SetBool("idle_normal", false);
             anim.SetBool("attack_short_001", false);
             anim.SetBool("move_forward_fast", false);
             uzunsaldırı = false;
             saldırı = false;
             hareket = true;
             hızlıhareket = false;
             durmak = false;
             dc = false;
             transform.Translate(0, 0, -1 * Time.deltaTime * hiz);
             print("at");
         }
         if (yorgunluk <= 0)
         {
             yorgunluk = 0;
         }
         if (yorgunluk >= 0)
         {
             yorgunluk -= 2.5f * Time.deltaTime;
         }
         if (Input.GetKey(KeyCode.LeftShift))
         {
             zaman -= 75f * Time.deltaTime * 4f;
             uzunsaldırı = false;
             saldırı = false;
             hareket = false;
             hızlıhareket = true;
             durmak = false;
             dc = false;
             anim.SetBool("move_forward_fast", true);
             anim.SetBool("attack_long_001", false);
             anim.SetBool("move_forward", false);
             anim.SetBool("idle_normal", false);
             anim.SetBool("attack_short_001", false);
             yorgunluk += 10f * Time.deltaTime;
             hiz = 10f;
         }
         else
         {
             hiz = 7.5f;
         }

         if (yorgunluk >= 100)
         {
             yorgunluk = 100;
             hiz = 7.5f;
             if (hızlıhareket == true)
             {
                 if (hareket == true)
                 {
                     anim.SetBool("move_forward_fast", false);
                     anim.SetBool("move_forward", true);
                 }
             }
         }
         //aclik -= 0.67f * Time.deltaTime;
         if (can >= 100)
         {
             can = 100;
         }
         if (can <= 0)
         {
             //Respawn();
             //can -= Time.deltaTime * 5;
         }
         if (can > 0 && can <= 50)
         {
             can += Time.deltaTime * 1.1f;
         }
         if (can > 0 && can <= 100)
         {
             can += Time.deltaTime * 0.75f;
         }
         if (mana <= 50)
         {
             mana += Time.deltaTime * 1.1f;
         }
         if (mana <= 0)
         {
             mana = 0;
         }
         if (mana <= 100)
         {
             mana += Time.deltaTime * 0.75f;
         }

         cantext.text = "Health: " + can.ToString("f0");
         manatext.text = "Mana: " + mana.ToString("f0");
     }
     
     [PunRPC]
     private void SyncProfile(string p_username, int p_level, int p_xp)
     {
         playerProfile = new ProfileData(p_username, p_level, p_xp);
         playerUsername.text = playerProfile.username;
     }
 }

}

belirti.png (17.3 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

238 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

my multiplayer game second player not active 0 Answers

ReplacePlayerForConnection works but... 0 Answers

Destroy player on spawn if he already exists in scene 1 Answer

Spawn Player when Room Starts - (Multiplayer) 1 Answer

playerControllerId higher than expected 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges