Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

so I am making multiplayer game and I stuck on one thing, I have blood overlay canvas in my scene(you know, in fps games if somebody shoots you your screen becomes red and this stuff), and when I shoot enemy, his screen becomes red, but mine also.

thats what i ahve now: if raycast hits enemy, player script calls: ColorController.MakeItred(); color controller is attached to this canvas image, here is its code:

`

 void Start () {
       if (current == 100 || current == 0)
        {
        opacity = 0;
        }
    }


// Update is called once per frame
void Update () {
          image = GetComponent<Image>();
    image.color = new Color32(reds, greens, blues, opacity);

    if (current == 0)
    {
        opacity = 0;
    }
    if (!playing)
    {
        if (opacity > 0)
        {
            StartCoroutine(toLower());
        }
        }
    if (opacity == 255)
    {
        playaudio();

    }

}

public static void MakeItred()
{
    opacity = 255;

}
public static void MakeItOff()
{
    opacity = 0;

}
 void playaudio()
{
    AudioSource audio = GetComponent<AudioSource>();
    audio.Play();
}
private IEnumerator toLower()
{
    playing = true;
    opacity -= 1;

    yield return new WaitForSeconds(interval);
    playing = false;
}`

btw thats function in player code that calls colorcontroller.makeitred,

[ClientRpc] public void Rpcdoit() { ColorController.MakeItred(); }

-Nick thanks.

share|improve this question
    
There could be a million reason why this happens. To diagnose the problem we would need to know how you implemented the triggering of the screen overlay effect and your networking. But you aren't posting anything about this, so unfortunately this question can not be answered. – Philipp Apr 13 at 9:14
    
@Philipp yes, I will add details – Nick Apr 13 at 9:33
up vote 2 down vote accepted

You method makeItRed is a static method which sets a variable which is most likely also declared as static. Static variables share their value between all instances of the class. Call the method on one instance of ColorController and you affect them all.

So make opacity, MakeItred and MakeItOff non-static variables and have the raycast hit code (which you did not post) call GetComponent<ColorController>().MakeItred() on the object where the raycast-hit was successful.

Also, the ColorController component should check if the gameObject it is assigned to is the local player and only then affect the overlay graphic.

share|improve this answer
    
so, I have to assign colorController code to player yes? – Nick Apr 13 at 11:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.