Object always active in Unity - c#

I am making my first 3D Unity game and I've encountered an issue where my sniper rifle game object is always active and I have no idea why. (I have multiple weapons and switch between them via a weapon switcher using the mouse wheel/number keys as input) it is active even when other weapons are active causing them to clip through each other during gameplay.I have confirmed that it is not my code causing the issue. I think it might be something to do with my animations? I really don't know. If you need more images or code snippets leave a comment or answer.
Animator

Related

How do I use trigger to destroy blocks on quest 2 unity?

I am making a game in Unity that is a combination of gorilla tag and minecraft and I am having trouble with using the RawAxsis1D.RIndexTrigger (top right quest 2 controller trigger) to destroy objects. (Some of my objects I'm trying to destroy have children.) I am also using raycasing so that it will make it so it will destroy the object the player is looking at, so far everything I have tried has failed.
Can anyone help me out? I am happy to provide any further info.
Main problem: when I add my script to my player, it did not do anything when the trigger was hit.

Unity Object bounces even before colliding with a boundary collider

Im making a carrom kind of game where Im using physics for striker movement, the problem is my striker object bounces from the edge of the board even before there was a real collision between my striker object collider and the board edge colliders.
Please check this video where I have highlighted my project setup, is I'm doing anything wrong here?
https://drive.google.com/file/d/1xifD--sXHvQWjLbud-Lpt-qG3GAXu-hS/view?usp=sharing
I tried to fix it in many ways but wasn't able to reduce this offset and without resolving this issue I wasn't able to proceed further, because if there are 2 objects very near to each other and if the striker hits only one of those objects accurately still the nearest another object is also considering it as a collision even though there wasn't a real collision!
Is this a known bug? if not how can I remove this offset and can have accurate collisions that are required for carrom kind of games (where multiple objects are near to other)?
I got the mistake that I have done!
In the editor, every time while going to play mode striker object collision detection mode was set to "Continuous Speculative" and at run time I used to change it to "Discrete" or "Continuous" or "Continuous Dynamic" assuming I will be able to change it at run time but that's not the case, even though editor allows us to change collision detection mode at run time, technically it will only consider the mode which was set initially(i.e while starting the play mode), so If I have to see the behavior of "Continuous Dynamic" then I have to stop the play mode and set collision detection mode to "Continuous Dynamic" and run it again!

I am using unity to make my first 2d game (im a noob) and i tried to make a death barrier that will teleport the charecter back to the start

(just so you know, im a noob at this so if you recognise some of the code it might of come from tutorials because i do not know C# and only know the parts that are similar to arduino and java; some of the code from the tutorials were edited so i cannot troubleshoot by looking at them; i have browsed the web)
also, it uses the sunnyland and free platform assets packs from the asset store because i am not an artist
so, i was trying to make a death barrier for the tutorial level (which is the only level in the platformer at the time of writing) and it didn't really work, so i tweaked the code until i got this:
public Transform respawnArea;
public GameObject player;
void OnTriggerEnter2D(Collider2D other) {
Debug.Log("the player has died"); //this is how i noticed the problem
player.transform.position = respawnArea.transform.position;
}
after that, i tested it and then it seemed to not work but then some further testing proved that the sprite was falling past the barrier but the collisions were teleporting where the should of went. i tested it with the debug and when the player fell through it reported it to debug but then i tried walking left (into a wall) and watched the debug and nothing happened but when i jumped over the wall, the invisible hitbox fell back into the death barrier and it gave me another debug. the weird thing is, when i pause the sprite appears where it would be and when i resume it disappears again. (again, im a unity and C# noob so this might be normal and have nothing related to the problem)
Unity Version: 2019.4.0f1
Unity hub is installed
Free version
For this, you should have a player object with a 2d collider set to trigger (checking the little box on the inspector "IsTrigger"). Also, the death barrier probably should have that checkbox marked.

Unity Multiplayer Cube Auto Move?

I have followed the Unity official Multiplayer Guide below and everything works, except for the fact that when I run two instances on the same computer (1 in build run and the other in the play mode) the characters for some reason auto move in a circle.
I have no idea why this is since I have followed the tutorial exactly, unless I missed something :P I am currently on step 9 (identifying local player) and I stopped there cause my players keep moving in circles.
To Clarify, they aren't spinning in place, they are walking in a circle. Just imagine a person following a dotted circle on the floor, same idea.
This issue only happens when i run two instances (build run mode and play mode in unity). if i try only the play mode in unity, everything works fine.
Has anyone experienced this before?
Unity Multiplayer Tutorial: https://unity3d.com/learn/tutorials/topics/multiplayer-networking/network-manager?playlist=29690
I am on version 2017.2.0f3 <-- maybe this is why? should I update to a different patch?
Thank you in advance
Where I spawn the characters
build and run, player just moves in circles automatically
both build run and play mode, they both again moves in circles automatically
I see a first issue in your code:
PlayerController.cs line 36, you wrote
var bullet = (GameObject)Instantiate(BulletPrefab, BulletSpawn.transform.position, BulletSpawn.transform.rotation);
it should be
var bullet = (GameObject)Instantiate(BulletPrefab, BulletSpawn.position, BulletSpawn.rotation);
Since BulletSpawn is already a Transform. Otherwise bullets might not fire in the gun direction.
I don't have any of the player moving without me pressing keybord key.
Here is a screenshot of 2 build run working good:
I also tried Build run + Unity Editor in game mode, I had no problem.
Maybe the problem comes from your keyboard or the input manager of unity ? Since you are using Input.GetAxis, check this https://docs.unity3d.com/Manual/class-InputManager.html
The issue with your character automatically moving is because you have something plugged into your computer that acts as a controller/joytick. Go into settings for controls and set all joystick to the last joystick #. Make sure you set this for all vertical and horizontal movement. That should do the trick.
For example, if you use a 3D mouse like 3D connexion, it could act as a joystick/controller and auto move your character.

Unity - Saving Level Changes

I am making a small RPG and a problem came up when I enter my house where there is a chest and I opened the chest to get an item, I then leave the house which changes the scene and come back into the house with the chest still able to be opened.
What I am looking for is when certain items (such as chests) are opened they stay opened throughout the game even on scene changes. There is probably more than one way to handle this but the only thing that came to mind was maybe using PlayerPrefs but I wanted to get some feedback if anyone had an easier way of approaching something like this.
I suppose, you want to save state of the scene with chest object. You shouldn't allow unity engine to destroy your chest object when entering next scene.
Use this method
DontDestroyOnLoad (transform.gameObject);
Read more on the Unity3D website.

Categories

Resources