unit – PlayClipAtPoint () playing multiple times at the death of the enemy

I have problems with PLayClipAtPoint(). I want to play a given sound as soon as a gameObject is destroyed. Here is my code (the parties involved):

void Update()
    if (health <= 0)

public IEnumerator Death() {
    anim.SetBool("isDying", true);
    AudioSource.PlayClipAtPoint(dmgSounds(0), transform.position);
    Destroy(gameObject, 3f);

    yield return null;

I guess the problem is due to the fact that as soon as the conditions are met, in this case the health reaches zero, the corutine starts and continues to start for each image, but how else to call it? Someone has a hint to give?

EDIT: I've already tried to wrap the logic in a bool as suggested in the comment so that it only works when the bool condition is valid, without success. Here is the code with the flag bool:

void Update()
    if (health <= 0)
            isAlive = false;

Unit – Automatic Keys with Controller Assistants

I've stripped and made up a human character with IK / FK and auxiliary objects to control the position of IK lenses and the rotation of bones. For example, the IK lens of the character's left arm is associated with a one-time wizard, which facilitates selection and movement and allows the arm's IK to solve the problem accordingly.

The skeleton (without the wizards) is configured as an avatar in Unity and I wish to use this platform to create and export animations in order to work with the avatar.

I create animations by moving the wizards in Auto Key mode in 3DS Max so that when the wizards are moved, their new transformation details (pos, rot, scale) are saved in keyframes.

My question is this: the use of the automatic key only records the transformation of the aids I'm moving, but not the bone transformations, even if they have been changed by moving the related aids. Is there a way to record bone positions using the automatic key with this calibration method or do I need to select the bones assigned to each movement and use Set Key?

unit – Networking – assigning identifiers to entities

I may be asking a silly question, but this problem bothers me …

So I have my network game in Unity (client) and my server written in C # (without Unity). I use the ENet library for networking. Most networked components are written by myself (lobby, components, etc.).

The server does not know Unity entities such as players, obstacles, and so on.
In most cases, I send a message ("hidden object with ID 4") to the server, which forwards this message to other clients to which they have applied the information.

What is my problem, how to assign the appropriate credentials to networked objects, which will be the same for all players?

What I do is that:

1. On all clients I get all components with specific network component (e.g. NetworkRigidbody)
2. I sort all of objects using special comparer which compares based on component name with all parents appended to it
3. ID is just an index in sorted array

The algorithm above works, but I have the feeling that in normal games this problem is treated in another way.

I've searched in the source code of Mirror, MLAPI and other libraries and I have not found how the entity id is generated, especially when the server does not. Is not a Unity application

unit – Drag a Rigidbody2D without passing obstacles

I have this body of code written for an object that must be an obstacle and another object that can be moved. I have colliders on both and a kinematic rigid body on the movable object, but the obstacle still allows to drag the object moved. That's all 2d. I'm not sure what I'm doing wrong.

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class Block : MonoBehaviour
    public GameObject Four_Object1;
    //public GameObject clone_Four_Object1;
    //private Vector3 screenPoint;
    //private Vector3 offset;
    private Rigidbody2D rb2d;
    private Vector3 screenPoint;
    private Vector3 offset;
    private Vector3 cursorPosition;

    public void Start()
        rb2d = GetComponent();
        GetComponent().isKinematic = true;

    public void OnMouseDown()
        screenPoint = Camera.main.WorldToScreenPoint(Four_Object1.transform.position);

        offset = Four_Object1.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));

    public void OnMouseDrag()

        Vector3 cursorScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
        cursorPosition = Camera.main.ScreenToWorldPoint(cursorScreenPoint) + offset;
        transform.position = cursorPosition;

    public void FixedUpdate()


unit – String access based on score

You can use a list for that (not sure of the exact syntax in C #):

List lists = new List();
lists.Add( new string(){"a", "b", "c"});
lists.Add( new string(){"v", "t", "d"} );
lists.Add( new string(){"e", "a", "b"} );
lists.Add( new string(){"g", "q", "z"} );


string() myList;
if ( counter >= 1 && counter <= lists.Count )
    myList = lists(counter - 1);
    myList = lists(lists.Count - 1)

You can also achieve this with a dictionary (again, not sure of the exact syntax in C #):

Dictionary scoresTexts = new Dictionary();

scoresTexts.Add( 1, new string(){"a", "b", "c"});
scoresTexts.Add( 2, new string(){"v", "t", "d"} );
scoresTexts.Add( 3, new string(){"e", "a", "b"} );
scoresTexts.Add( 100, new string(){"g", "q", "z"} );


string() myList;
if (!scoresTexts.TryGetValue(score, out myList))
    myList = scoresTexts(100);

In any case, I think DMGregory's answer suggests more effective approaches than those proposed here.

unit – How to send a friend request using Play fab?

I'm doing a multiplayer game.

I create a Playfab account then I add a titleid in playfablogin.cs, then run my script and then the unit says: Congratulations, you made your first API call successful!

I want to send it to a friend Player1-> Player2 application using playfab. But I have no idea for the next step ??

How to send a friend request Player1-> Player2 ??

unit – Moving an object to random points Unity3d c #

So here is the problem
I want to change the gameObject position to specific points that I've declared with empty objects at random, but the problem is when the object reaches one of the points for which it starts to tremble and not to repeat the same thing
here is my code

public class EnemyController : MonoBehaviour {

public Transform() movePoints;
public float speed;
private int amount;
private Transform currentTarget;

void Start () {
    randoming ();


void Update () {
    Movement ();

void randoming(){
    amount = Random.Range (0, movePoints.Length);
    currentTarget = movePoints(amount);

void Movement(){
    transform.position = Vector3.MoveTowards (transform.position, currentTarget.position, speed * Time.deltaTime);
    StartCoroutine (startMoving());

IEnumerator startMoving(){
    yield return new WaitForSeconds (5.05f);
    randoming ();


unit – How to keep the texts of the user interface in their positions relative to all screen resolutions?

I need to position several user interface texts on the screen.

I do it using a canvas with overlay screen.

In addition, these UI texts must remain at their relative positions for different screen sizes.

Here is a screenshot in which the texts are highlighted in green:

enter the description of the image here

We can see that they do not follow a pattern similar to a grid.

How could I keep them at their relative position at different screen resolutions?

Thank you.

unit – How to build this collision vector?

I have a 3D game, but for the movement, I only use two axes (X and Z) – X is vertical, Z is horizontal

Here is what I try to achieve:

enter the description of the image here

The player is the circle, InputDirection is blue, NewInputDirection is green.
I struggle to get the desired green direction.

Image 1
The player goes up (he pushes on the wall)

InputDirection: (-1f, 0f, 0f)

NewInputDirection: (0f, 0f, 0f) because we should stop him.

Image 2
The player moves to the wall and down. When it reaches the wall, its horizontal axis must be blocked – set to 0, it slides

InputDirection: (0.5f, 0f, -0.5f)

NewInputDirection: (0.5f, 0f, 0f)

Image 3
Same as above, but the wall is rotated.

Right now, my code looks like this:

RaycastHit hit;
bool collides = Physics.Raycast(this.playerRigidbody.position, inputDirection, out hit, 1f); // ray in front of the player

if(collides){ // if there's a collision
    // calculate the direction from the player to the collision contact point
    Vector3 collisionNormal = (hit.point - playerRigidbody.position).normalized;
    // idk...

I do not know how to calculate it. I have tried different ways. Should I also consider the rotation of the wall?

unit – When do you use StartCorutine and when is Invoke?

Invoke is useful if you want to do something once.

A coroutine can pause, let the game continue to work, then do something else later. This makes them useful for processes that last in time. In addition, you can pass arguments to a coroutine. The Invoke method does not allow this.

Example of a coroutine that implements a countdown timer:

 IEnumerator Countdown(int seconds)
       while (seconds > 0) {
            yield return new WaitForSeconds(1f);

You can now use this function to count down an arbitrary length. For example, if you want to start a 10-second countdown, call


However, if you want to do something in 10 seconds without having a visible countdown before the event, then it would be easier to use Invoke:

 void Go()

 Invoke("Go", 10f);