- Home /
Question by
nibek1000 · Jun 11, 2018 at 06:15 AM ·
c#networkingplayer
Networking get local player
Hi. Im trying to get by script only player that play on device. It always take host player. The script change speed of player when it is on trigger. This is what I got so far:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OnTriggerSlow : MonoBehaviour {
public GameObject player;
public GameObject race;
public GameObject stay;
public int found = 0;
// Use this for initialization
void Update()
{
if (player = null)
{
player = GameObject.FindGameObjectWithTag("Player");
Debug.Log("Looking for PLAYER");
}
race = GameObject.FindGameObjectWithTag("raceS");
stay = GameObject.FindGameObjectWithTag("stayS");
if (found == 0 & player != null)
{
player.tag = "PlayerF";
found = 1;
}
}
void OnTriggerStay2D () {
//for (int i = 0; i < player.Length; i++)
player.GetComponent<CarBehavior>().max_power = 15;
Debug.Log("slowed");
StartCoroutine(Example());
//stay.SetActive(true);
//race.SetActive(false);
}
IEnumerator Example()
{
yield return new WaitForSeconds(1);
//for (int i = 0; i < player.Length; i++)
player.GetComponent<CarBehavior>().max_power = 35;
//stay.SetActive(false);
//race.SetActive(true);
}
}
The problem is that whatever I do it always take host. Script that I gave does not work as I want.
This script take always host:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OnTriggerSlow : MonoBehaviour {
public GameObject player;
public GameObject race;
public GameObject stay;
// Use this for initialization
void Update()
{
player = GameObject.FindGameObjectWithTag("Player");
race = GameObject.FindGameObjectWithTag("raceS");
stay = GameObject.FindGameObjectWithTag("stayS");
}
void OnTriggerStay2D () {
//for (int i = 0; i < player.Length; i++)
player.GetComponent<CarBehavior>().max_power = 15;
Debug.Log("slowed");
StartCoroutine(Example());
//stay.SetActive(true);
//race.SetActive(false);
}
IEnumerator Example()
{
yield return new WaitForSeconds(1);
//for (int i = 0; i < player.Length; i++)
player.GetComponent<CarBehavior>().max_power = 35;
//stay.SetActive(false);
//race.SetActive(true);
}
}
Any ideas? Im new at networking so Im sorry if that is silly question ;) Thanks!
Comment
Your answer
Follow this Question
Related Questions
Send information from one player to another. Unity Multiplayer 2 Answers
Player names all displayed as local player 1 Answer
Multiple Cars not working 1 Answer
Lock on opponent in UNET (C#) 1 Answer
Network Game Player reference 0 Answers