unit – How to change the value of a global class variable in a function attached to the UI button?

public class ControlCar : MonoBehaviour
   int gear=0;
    public void onChangeGear(int gear_no)
        gear = gear_no;


In the above code, I attached onChangeGear to Button using Inspector.When the button is pressed, the value of the gear does not change.I think that 39; a separate copy of the function is created for Button. How can I change the value of the equipment?

unit – Why doesn't OnCollisionEnter work?

This script is attached to the wall (Cube 3D) with a box collider:

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

public class LockedRoomTrigger : MonoBehaviour
    private void OnCollisionEnter(Collision collision)

But when the player moves and touches the cube, he does not reach the Debug.Log I used a breakpoint on the Debug.Log line.

A screenshot of the cube wall with the box collider component and the script attached to it.
The problem is not with the player because if I move with the player near the doors, they open so that the player triggers things and does not walk through the walls.

Do not collide

This is a screenshot of NAVI.
NAVI is a little in front of the player and moves with the player and part of the player in the game like an assistant friend.

NAVI is the one who collides and knocks on things if the doors do not partition the player since the NAVI is a little in front of the player.

NAVI only has one box collider:


And here are the player Inspector screenshots. I will add two screenshots as it does not fit into a single screenshot:

The player is a first-person view:



Trying to create an Android problem in the unit

Hi, I am planning to download my game from the Play Store, but I still get this message when I try to create. What can I do to resolve this obstacle ???

Message when trying to build

The generation parameters are as follows:

enter description of image here

unit – The small health bar above the entity is drawn differently when the entity rotates differently

Here is a simple positioning code for my health bar:

transform.position = Camera.main.WorldToScreenPoint(target.position - 0.2f * target.up);

Here is the prefab:

enter description of image here

  • HealthBar is anchored in the center-center and rotates at 0.5, 0.5,
  • The background and fill are stretched and rotated by 0.5, 0.5, but the background is positioned left, right, top and bottom.

Here's what it should look like: (all images are enlarged)

enter description of image here

And here is a video about the entity that revolves around: https://i.imgur.com/EOzFEvt.mp4

2 examples of rotations, in which the health bar is not drawn correctly:

enter description of image here

enter description of image here


Edit: Origin of the entity:

enter description of image here

unit – Limit swing limits 1 and 2 on the articulations of characters asymmetrically

I want to create a game object that looks like the creatures seen here. A CharacterJoint is perfect for me, but I can't find a way to limit the limits of swing 1 and swing 2 asymmetrically, which can be done easily for the torsional limit.

One approach I tried was to write a script that will rotate the body beforehand, then add the joint. It didn't work for me and I was wondering if there could be a simple way to do it that I miss. If there are none, I will add the script to my question.

unit – Scale / non-uniform scale is not applied to the entity

I'm just learning the new Unity DHWs and I'm trying to change the size (scale) of an entity.
Everything works fine, I can change the rotation, the position but not the scale.

I wonder why.
I have done various tutorials, I have tried Scale, NonUniformScale, LocalToWorld, CompositScale but nothing works. Maybe some methods are out of date.

Here is what I have tried so far.

I have several prefabs (plans) that are generated correctly and each of them having a transformation component.

enter description of image here

Now I want to change the scale of all planes.
For this, I use a JobComponentSystem.
In the following piece of code, the rotation works fine, but not the scaling.

I tried LocalToWorld.

public void Execute(ref Rotation rotation, ref LocalToWorld scale) {
            rotation.Value = math.mul(rotation.Value, quaternion.RotateZ(math.radians(0)));
            scale.Value = float4x4.Scale(2, 4, 5);

I tried NonUniformScale

public void Execute(ref Rotation rotation, ref NonUniformScale scale) {
            rotation.Value = math.mul(rotation.Value, quaternion.RotateZ(math.radians(0)));
            scale.Value = new float3(2, 1, 4);

I tried Scale.

public void Execute(ref Rotation rotation, ref Scale scale) {
            rotation.Value = math.mul(rotation.Value, quaternion.RotateZ(math.radians(0)));
            scale.Value = 5;

None of this works.
What have I done wrong (the scale is just 10,10,10) or what is the best way to do it right now?

How can I put the pedal of a car in the unit?

I am trying to create a 2-D car game in the mobile unit where the player controls acceleration by sliding the pedal on the touch screen. My idea of ‚Äč‚Äčimplementation is to use the user interface slider. Is there any other good I can use? Please suggest any other implementation, if any. I am new to this field.

unit – Game construction hangs when loading scene

I built my project on Android to do tests and stuff, but I can't go any further than the main menu scene. I built it previously and it worked well. Now that I'm trying to load level0, it crashes without error message from Adb Logcat. Quit the game and that's it. It works well in the editor.

I have tried several things. I changed the color space from front to back, I built my addressables, tried the integrated development and the non-development, and the binary checkbox of the application Split is also false …

Unity 2019.2

My adb catlog outing

unit – Rigidbody seems to tremble when placed as a brother to a first-person camera

In my game, the player can pick up an object (which is related to the camera in the first person), or the player can push an object (which is related to the player, but not his camera in the first person). Both mechanics use very similar implementations when it comes to moving objects, but I get a fairly large amount of “ perceived '' jitter. Pushing – the object, as far as I know, is not actually shaky.

(Side note – I didn't know where to download images, so I used mega ones which can be used just to view the images)

Thrust images, with visible jitter

Elevator images for comparison

Thrust images but related to the camera in the first person

Frame-by-frame push images from the side at a scale of 0.50

Frame-by-frame elevator images at a scale of 0.50

The object is moved to FixedUpdate and the camera is moved to LateUpdate. You can see quite clearly that in the side view, the camera is moving after the object. Since the object is the parent of the camera on Lift, it moves with it and no change is seen. However, on Push, it does not move and therefore seems to tremble.

I do not know how to solve this problem. I have tried:

  • Allow interpolation on the rigid body,
  • Disable gravity on the rb / take off from the ground (for example, not caused by a collision with the ground),
  • Do not parent the object at all to the reader (the object is always perceived as trembling because the camera moves in LateUpdate out of synchronization with the object)
  • Object parenting on camera (but this is not intentional as they are only meant to push causes all kinds of rotation problems etc. – but the jitter is stop as seen in the third link),
  • The following code in LateUpdate to push it forward –
    protected void CheckCameraPosition()
        if (m_LastCameraPosition == Vector3.zero)

        Vector3 newPosition = m_FPCamera.Transform.position;
        if (newPosition == m_LastCameraPosition)

        Vector3 newOffset = newPosition - m_LastCameraPosition;
        newOffset.y = 0f;
        Transform.position += newOffset;

But the object is still shaking and if I were to seriously consider the above code, I would be worried about the racing conditions since the camera movement is also executed in LateUpdate.

unit – enemy AI does not work as expected Unity3d

I have this very simple enemy AI that follows the player and is supposed to stop and shoot the player when he goes into a trigger, but it doesn't seem to stop not or does not shoot. This is one of my first scripts so it is not really good. Any help will be appreciated.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class EnemyAI : MonoBehaviour

    public GameObject Destination;
    NavMeshAgent agent;
    public Collider TriggerCollider;
    public GameObject Enemy;
    public GameObject bullet;
    public float EjectionForce;
    public float firingrate = 20f;
    private float NextFire = 0f;
    public GameObject GunArea;

    // Start is called before the first frame update
    void Start()
        agent = GetComponent();


    // Update is called once per frame
    void Update()

    void OnTrigger(Collider other)
        if (other.transform.tag == "Player" && Time.time >= NextFire)
            agent.isStopped = true;
            NextFire = Time.time + 1f / firingrate;
        else agent.isStopped = false;
    void AimAndShoot()
        GameObject enemybullet = Instantiate(bullet, GunArea.transform.position, GunArea.transform.rotation) as GameObject;
        enemybullet.GetComponent().AddForce(enemybullet.transform.forward * EjectionForce);
        Destroy(enemybullet, 1f);