'Unity2d pun2 kill player nickname problem.(Little english.)

When my player kill other player, I want to find death player nickname. How?



Solution 1:[1]

It depends on how did you keeping them in your code. The answers could be more helpful if you can provide more information about the situation.

But generally speaking, you can get all the information about the object in a collision. You can use that to get the relevant info about the player.

I tried my best to talk about the problem generally but I highly suggest you edit your question to have more information about your problem.

Solution 2:[2]

there are several way of this question, i was tryed this way:

string CircleNickName="sky";
string SquareNickname="sun";
Rigidbody2D body;
Rigidbody2D squareBody;

float horizontal;
float vertical;
Vector2 move;

public float runSpeed = 2.5f;

void Start()
{
    body = GetComponent<Rigidbody2D>();
    squareBody=GetComponent<Rigidbody2D>();
}

void Update ()
{
    horizontal = Input.GetAxis("Horizontal");
    vertical = Input.GetAxis("Vertical"); 
    //move.x = horizontal;
    //move.y = vertical;
}

private void FixedUpdate()
{  
    body.velocity = new Vector2(horizontal * runSpeed, vertical * runSpeed);
}
private void OnCollisionEnter2D(Collision2D other) {
   if(other.gameObject.tag=="square"){
      Debug.Log(SquareNickname);
      Destroy(squareBody);
   }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ErenErdogan
Solution 2 Fibonacci