r/UnityHelp • • Jan 29 '23

UNITY Jumping trouble!

3 Upvotes

Im new in unity
I want the object to change position smoothly. instead it abruptly changes

my logic for the objects movement is:

is there anything wrong with the logic? or should i use addForce instead of changing position?


r/UnityHelp • • Jan 06 '23

UNITY Any reason why I can't load in the 3D game kit template in the Unity Hub?

3 Upvotes

So I just downloaded Unity Hub and Editor, as I plan on using integration with Wwise to make part of my showreel in game audio. The reason I'm choosing to work with Unity specifically is that the 3D Game Kit seems like a great level to work with, as far as designing and implementing sounds goes. However, I'm struggling to load the 3D Game Kit into Unity, despite being able to start a project with the 2D Platformer Microgame.

Is there anything in particular I'm missing here? I have the 3D Game Kit saved to my assets, when I click 'Open in Unity' though, all I get is a loading screen which disappears a few seconds later, as shown in the images below.

If anyone else has experienced this kind of problem, I would massively appreciate any help resolving this issue.

Thanks!


r/UnityHelp • • Dec 28 '22

Player shoots up when The quarterdeck moves up

3 Upvotes

Hi! Thank you for helping me out. I'm trying to make a game where the player sails in a pirate ship. i'm trying to add a first person player, but the player slides off the surface*, and when i managed to fix it, i noticed the player bounces up, and eventually falls off the ship due to the jostling.

Is there any way to make this work?

any help appreciated, i'll share whatever we need to fix this

*= i fixed it by creating an extra collider which is set as a trigger, and when its triggered, i parent the player to the ship.


r/UnityHelp • • Dec 14 '22

Reference becomes null after it's used once and I don't know why

Post image
3 Upvotes

r/UnityHelp • • Dec 08 '22

SOLVED Modifying the ezy-slice code

3 Upvotes

I am using a cutting mechanic that uses the ezy-slice script by David Arayan. I have already modified it to allow one to cut an object up further than just into two pieces, and here's my modified version of the Slicer.cs code:

using UnityEngine;

using EzySlice;

public class Slicer : MonoBehaviour

{

//accesses what material sliced objects become

public Material materialAfterSlice;

//checks if objects are on the slicable layer

public LayerMask sliceMask;

//checks if it makes contact with slicable objects or not

public bool isTouched;

private void Update()

{

//runs if the collider interacts with a slicable object

if (isTouched == true)

{

//turns it off

isTouched = false;

//checks if the slicable objects have made contact with the rigidbody

Collider[] objectsToBeSliced = Physics.OverlapBox(transform.position, new Vector3(1, 0.1f, 0.1f), transform.rotation, sliceMask);

//creates the new slices

foreach (Collider objectToBeSliced in objectsToBeSliced)

{

SlicedHull slicedObject = SliceObject(objectToBeSliced.gameObject, materialAfterSlice);

//creates the new slices

GameObject upperHullGameobject = slicedObject.CreateUpperHull(objectToBeSliced.gameObject, materialAfterSlice);

GameObject lowerHullGameobject = slicedObject.CreateLowerHull(objectToBeSliced.gameObject, materialAfterSlice);

//positions the new slices

upperHullGameobject.transform.position = objectToBeSliced.transform.position;

lowerHullGameobject.transform.position = objectToBeSliced.transform.position;

//accesses the function for applying physics to the slices

MakeItPhysical(upperHullGameobject);

MakeItPhysical(lowerHullGameobject);

//gets rid of the original object

Destroy(objectToBeSliced.gameObject);

}

}

}

//gives the slices rigidbodies and convex colliders

private void MakeItPhysical(GameObject obj)

{

obj.AddComponent<MeshCollider>().convex = true;

obj.AddComponent<Rigidbody>();

//allows for further slicing (done by me)

obj.layer = LayerMask.NameToLayer("Cuttable");

//calculates volume from the length, width, and height of the slice collider (done by me)

float volume = transform.localScale.x * transform.localScale.y * transform.localScale.z;

//retains object density (done by me)

float density = 1141;

//calculates mass from density and volume (done by me)

obj.GetComponent<Rigidbody>().mass = volume * density;

}

private SlicedHull SliceObject(GameObject obj, Material crossSectionMaterial = null)

{

//returns a value that is sliced objects

return obj.Slice(transform.position, transform.up, crossSectionMaterial);

}

}

I have given it to an object in VR that you can pick up and carry, but it won't apply the script that lets you do that for the pieces. How do I modify the script to let individual fragments be picked up and held?


r/UnityHelp • • Dec 04 '22

SOLVED Hi, for some reason, visual studio 2022 doesn't help me auto-completing the code, and I don't know the reason why.

3 Upvotes

r/UnityHelp • • Dec 04 '22

UNITY Unity Shader Graphs - How to Update Instanced Material's Shader's Keyword Property from within script???

3 Upvotes

Does anyone know how to modify a Material's Shader's Keyword variable using a C# script? I have a Shader Graph with nested Subgraphs that is being instanced by GameObjects in the scene (material = GetComponent<SpriteRenderer>().material).

Weirdly, it actually works perfectly when I modify the variables in the MaterialPropertyBlock in the Unity Editor, however when I try to change the variables within the script, either by:

1 - m_Material.SetFloat("_MODE", 1f);

or 2 - b.SetFloat("_MODE", 1f); GetComponent<SpriteRenderer>().SetPropertyBlock(b);

The Sprite no longer updates within the scene correctly. For clarification, the actual values in the Editor inspector change but the Material no longer behaves ie renders correctly.

This has been a really weird one - anyone have any ideas?

More than happy to provide more detail about the scripts, shader graph, or anything else


r/UnityHelp • • Dec 02 '22

Resizing Elements For Differing Resolutions

3 Upvotes

Hi all,

I'm trying to make a small mobile application for my friends and I to use, but I'm running into an issue with resizing elements for different resolutions. I've tried looking it up, but nothing I have found has helped.

When on my phone's resolution, this UI element is in the correct position with the correct dimensions:

However, when I change the resolution to something much shorter, the UI element is still in the correct location, but the dimensions get thrown off, and even expand off of the canvas:

I've tried anchoring them to their respective corners and limiting their min and max anchors, but they seem to break out of those set boundaries whenever the screen is resized and I can't figure out why. If anybody happens to know a way to fix this, the help would be greatly appreciated!

Thanks!

Also, I know some of the other stuff also gets funky, but that's because I haven't properly set them up to resize since it wasn't working properly with these other elements first.


r/UnityHelp • • Dec 02 '22

Mirror Networking Exception Out of Nowhere

Thumbnail
gallery
3 Upvotes

r/UnityHelp • • Nov 19 '22

PROGRAMMING [Netcode] cannot start client while an Instance is already runnig

3 Upvotes

I am getting this error when I'm entering my friends lobby and my character doesn't spawn. anyone knows why?


r/UnityHelp • • Nov 10 '22

TEXTURES Need help with textures

3 Upvotes

I baked the texture from blender and some of the textures applied properly on the model but the rest arent positions correctly do i need to be changing how im baking or is it something in unity?

this is what it looks like


r/UnityHelp • • Nov 02 '22

SOLVED Coding Mixer Groups to React to Triggers

3 Upvotes

Okay, I have created a mixer group with two snapshots. I am currently building a map for class, and I have assembled an indoor and an outdoor mixer group and have created a trigger that will activate once the player steps inside a building. What do I code to make the trigger access the mixer group and change the snapshot from the outdoor (default) to the indoor when I enter that trigger's box collider, and change it back to the outdoor snapshot when I exit the trigger?


r/UnityHelp • • Oct 30 '22

UNITY I want to put colliders on my VR rig's hands that let them press the button to turn the oven light on. How do I do that?

Post image
3 Upvotes

r/UnityHelp • • Oct 28 '22

PROGRAMMING Quest Help

3 Upvotes

Do you guys know any tutorial about quest system using scriptable objects specifically gather item quest?


r/UnityHelp • • Oct 27 '22

UI slow render?

3 Upvotes

I am very new to Unity. After installation on my Debian 11 Linux. I found a problem.

As I move through the menu or drag a dialog box, the output becomes weird and overlap. However, after moving the cursor to the problem area, the area comes back to normal. How can I solve this issue? Thanks in advance.


r/UnityHelp • • Oct 26 '22

When passing over 0 degrees rotation It goes backwards

3 Upvotes

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class trailer : MonoBehaviour

{

public Transform car;

public float x;

public float target_num;

public Vector3 pos;

void Start()

{

}

// Update is called once per frame

void Update()

{

x = car.rotation.eulerAngles.y;

if (x > transform.rotation.eulerAngles.y)

{

gameObject.transform.Rotate(0,.25f,0);

}

if (x < transform.rotation.eulerAngles.y)

{

gameObject.transform.Rotate(0, -.25f, 0);

}

transform.position = car.position + pos;

}

}


r/UnityHelp • • Oct 22 '22

Unity slider displaying different values

3 Upvotes

I have a game where you have a flashlight and a slider for fuel, when you run low on fuel you can pickup a canister to replenish 75f. The problem is that after you pickup the canister the slider displays the value before picking up when the flashlight is active. Any tips

here are all the instances of changing the slider value


r/UnityHelp • • Oct 19 '22

PROGRAMMING How to Move a Cinemachine Camera With Script, FOV and Follow Offset

3 Upvotes

I need help, I would like to know how do I animate the Cinemachine Virtual Camera in Follow Offset, I would like to change the y values. Well, FieldOfView can do it, because I want to use the FOV to do the ZoomOut and I wanted to use the Y to raise the camera a little. I am not getting it is working wrong. Note this camera has Player as Follow.

  1. CinemachineVirtualCamera _vCam;

  2. CinemachineTransposer cineTransposer;

  3. public float zoomSpeedFinish;

  4. public float X, Y, Z;

  5. public float PostT;

  6. private void Awake()

  7. {

  8. _vCam = GetComponent<CinemachineVirtualCamera>();

  9. cineTransposer = _vCam.GetCinemachineComponent<CinemachineTransposer>();

  10. }

  11. public void ZoomOutFinish()

  12. {

  13. _vCam.m_Lens.FieldOfView = Mathf.Lerp(_vCam.m_Lens.FieldOfView, 90, zoomSpeedFinish);

  14. cineTransposer.m_FollowOffset = Vector3.Lerp(cineTransposer.m_FollowOffset, new Vector3(X, Y, Z), PostT);

  15. }


r/UnityHelp • • Oct 11 '22

SOLVED I have made 3 scripts that communicate with each other. I want help making them communicate to create recipes that each have 3 ingredients that you must click on to put in the pot.

Thumbnail
gallery
3 Upvotes

r/UnityHelp • • Oct 03 '22

UNITY NotImplementedException: This functionality is not implemented in the portable version of this assembly.

3 Upvotes

trying to use InTheHand.Net.Bluetooth for my UWP app but it just gives me this:

NotImplementedException: This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.

And I have no idea what it actually means?

Anyone have an idea?


r/UnityHelp • • Sep 16 '22

OTHER I have a error where Unity says my script isn't connected. any help

Post image
3 Upvotes

r/UnityHelp • • Sep 15 '22

SOLVED Code issue

3 Upvotes

Hello r/UnityHelp.

I am trying to get into unity (again) I've had previous experience with the 3D engine but This time I'm trying to create a platformer using the 2D engine.

I've gotten to the platform which you can jump down from, I've decided to use bool as an variable that controls the collision but I have encountered two different issues (but one in particular has accord twice). I've tried googling any solutions (including official documentation) but haven't found one that I could understand. here are the two different errors:

1.Assets\PlayerMovement.cs(14,9): error CS0118: 'Animator' is a type but is used like a variable

2.Assets\PlayerMovement.cs(15,9): error CS1656: Cannot assign to 'SetBool' because it is a 'method group'

I have used Bool as a variable before in the 3D engine for a door that automatically opens but I've forgotten how I did it and I don't have the script to reference from. Anyway here is the script that I'm using (the jump line is an work in progress):

using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{ 
public Animator ani; 
private Rigidbody2D rb;
private void start()
 { rb = GetComponent<Rigidbody2D>();
     Animator = GetComponent<Animator>();
     Animator.SetBool = new ("Jump down", false);     
    } 
private void Update() 
    { if (Input.GetKey(KeyCode.RightArrow))  
       { rb.velocity = new Vector2(2f ,0f); //this will move your RB to the right while you hold the right arrow         }
if (Input.GetKey(KeyCode.LeftArrow))  
     { rb.velocity = new Vector3(-2f ,0f); //this will move your RB to the left while you hold the right arrow        }
if (Input.GetKey(KeyCode.UpArrow))  
     { rb.velocity = new Vector4(0f ,2f); //this will move your RB up while you hold the right arrow        }
 if (Input.GetKey(KeyCode.DownArrow))     
  { Animator.SetBool = new ("Jump Down", true);    
    } 
      } 
    }

(Sorry if this is in the incorrect formatting I don't know how to use the code format feature of reddit)

My Thoughts on this issue is with line 9 being incorrect and with the setbool lines being wrong but I don't know why.

I appreciate any help with my issues

~Ratbagdoo


r/UnityHelp • • Sep 14 '22

How to position a game object according to users gps location?

3 Upvotes

Hello,

So I have been trying to work out this code. I want to automatically place a game object in a position in the unity world space according to users GPS location.

So there exists a game object called player which has a capsule as representation of player and a topdownCamera to see the player in its surroundings. I want to place the player in the map according to the users GPS location.

This is the code which after much trying nothing is happening.

using System.ComponentModel.DataAnnotations.Schema;

using System.Threading;

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class GPS : MonoBehaviour

{

Vector2 Rinit;

Vector2 RCurrentPos;

Vector2 Finit;

Vector2 FCurrentPos;

public float Scale;

public GameObject player;

public bool FakingLocation;

// Start is called before the first frame update

void Start()

{

Input.location.Start(0.5f);

Input.compass.enabled = true;

Debug.Log("Hello!");

Finit = Vector2.zero;

}

IEnumerator UpdatePosition()

{

if(FakingLocation==false){

Debug.Log("Update Started");

if (Input.location.isEnabledByUser == false)

{

Debug.Log("Failed because User did not enable location");

}

int maxWait = 20;

while(Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)

{

yield return new WaitForSeconds(1);

maxWait--;

}

if (maxWait < 1)

{

Debug.Log("Initializing failed, try again");

yield return null;

}

if (Input.location.status == LocationServiceStatus.Failed)

{

Debug.Log("Location Service Status Failed");

yield return null;

}

else

{

Rinit = new Vector2(28.35f, 76.97f);

SetLocation(Input.location.lastData.latitude,Input.location.lastData.longitude);

}

}

else

{

SetLocation(100+Time.time , 100 + Time.time);

}

}

void SetLocation(float latitude,float longitude){

RCurrentPos = new Vector2(latitude,longitude);

Debug.Log(RCurrentPos);

Vector2 delta = new Vector2(RCurrentPos.x - Rinit.x, RCurrentPos.y - Rinit.y);

FCurrentPos = delta * Scale;

transform.position = new Vector3(FCurrentPos.x,0,FCurrentPos.y);

//Instantiate(player,player.transform.position,player.transform.rotation);

}

// Update is called once per frame

void Update()

{

StartCoroutine(UpdatePosition());

}

}

Please help! What am i mssing?

[1]: /storage/temp/199857-screenshot-2022-09-14-220236.png


r/UnityHelp • • Sep 13 '22

UNITY Unity UI Package Gone?

3 Upvotes

Hey all!

I'll keep it brief--I was trying to call upon the Unity UI package in my script, and kept getting error messages saying it couldn't find a definition. ( " Using UnityEngine.UI"; at the top of the script )

So I panicked and tried looking up solutions, and some people had recommended removing the Unity UI package from the project, then re-adding it. So I went to the package manager, removed it from the project, and then tried looking it up again to re-add it. However now it shows the Unity UI package as still being "added" and even in use within the project (with a TextMesh). But under the assets within project menu, the Unity UI package isn't found. So now I'm just lost--is the Unity UI package in a weird limbo state? Should I just restart everything? Will my code be even more broken now that I have/haven't removed the package?!

Please help!