r/UnityHelp • • Sep 11 '22

TEXTURES Not sure how exporting unity assets and then importing into other unity projects work with textures?

3 Upvotes
  1. I import my blender project into Unity, get it shaded, and then export it as a custom package. I go into another new project, and try to import that custom package into that, and it imports without the textures i put on them with unity. What am I doing wrong here?

  2. ***[7:37 AM]***I import it into a new unity project, along with the textures and materials that come with it, they're just not applied to the object. Can I somehow fix that, or is it easy enough to just reapply the textures


r/UnityHelp • • Aug 22 '22

Raycast in Unity2D

3 Upvotes

When using a Raycast with Physics2D how do I make it detect only one layer.

[Serialize Field] private LayerMask floor; 
RaycastHit2D hit;
hit = Physics2D.Raycast(transform.position, other.transform.position, floor);

The above is the same code except the point I am using as my Raycasts target is a specific GameObject. The Raycast works, but it always detects the player. I want it to detect only the layer set in the floor variable.


r/UnityHelp • • Aug 18 '22

UNITY Unity 2022 Sprite Shape - unable to select point mode

3 Upvotes

Hello, this is Dustin. After recently upgrading to Unity 2022 working on my platformer, I somehow can't find how to change the point mode for my sprite shape controller (Linear, Curved, Broken) when I'm editing my splines. Is there a fix to this? I would love to keep using this since my level design for this project favors picking between linear and curved points.


r/UnityHelp • • Aug 09 '22

UNITY need help super new to unity and camera is moving instead of the players

3 Upvotes

i know this is a super noob problem and im sorry for taking up your guys time but im super inexperienced with unity and am trying just to make simple pong while following a teutorial but for some reason when i enter play instead of my player1 and player2 moving neither move but the camera still moves with up and down i

i dont know why but for some reason the players dont move a muscle and the camera dosent zoom in on the level instead stays zoomed out and moving with the up and down arrows pls help

https://www.youtube.com/watch?v=YHSanceczXY the guide im following


r/UnityHelp • • Aug 04 '22

PROGRAMMING Help with error cs1061

3 Upvotes

I'm trying to follow this tutorial: https://www.youtube.com/watch?v=SlEgvvNYXQU but I get error cs1061 on line 36 character 67. It reads 'GameObject' does not contain a definition for 'GetComponenet' and no accessible extension method 'GetComponenet' accepting a first argument of type 'GameObject' could be found (are you missing a using directive or an assembly reference?)

Here is the script:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.UI;

namespace KeySystem

{

public class KeyCast : MonoBehaviour

{

[SerializeField] private int rayLength = 3;

[SerializeField] private LayerMask layerMaskInteract;

[SerializeField] private string excluseLayerName = null;

private KeyItemController raycastedObject;

[SerializeField] private KeyCode openDoorKey = KeyCode.Mouse0;

[SerializeField] private Image crosshair = null;

private bool isCrosshairActive;

private bool doOnce;

private string interactableTag = "InteractiveObject";

private void Update()

{

RaycastHit hit;

Vector3 fwd = transform.TransformDirection(Vector3.forward);

int mask = 1 << LayerMask.NameToLayer(excluseLayerName) | layerMaskInteract.value;

if (Physics.Raycast(transform.position, fwd, out hit, rayLength, mask))

{

if (hit.collider.CompareTag(interactableTag))

{

if (!doOnce)

{

raycastedObject = hit.collider.gameObject.GetComponenet<KeyItemController>();

CrosshairChange(true);

}

isCrosshairActive = true;

doOnce = true;

if (input.GetKeyDown(openDoorKey))

{

raycastedObject.ObjectInteraction();

}

}

}

else;

{

if (isCrosshairActive)

{

CrosshairChange(false);

doOnce = false;

}

}

}

void CrossHairChange(bool on)

{

if (on && doOnce)

{

crosshair.color = Color.red;

}

else

{

crosshair.color = Color.white;

isCrosshairActive - false;

}

}

}

}


r/UnityHelp • • Jul 31 '22

PROGRAMMING Losing 2 Lives Instead of 1 Please Help

3 Upvotes

My 2d platformer isn't working right. When I fall down under the platforms, I want to lose just one life. For some reason I always lose two. When I hit a boulder obstacle, I lose one life like I'm supposed to. Here's my project. It was made in Unity 2019.2.13f1 so you're going to have to download that from the archive if u want to follow along.

Please help me.

Thanks


r/UnityHelp • • Jul 28 '22

OTHER Converting Grayscale Roughness Texture to Unity Smoothness Texture

3 Upvotes

Title. I'm trying to use a grayscale I made in Blender for roughness to be the smoothness texture in Unity. I haven't had any success using alpha in the metalness slot. Does anyone know how to do this/know a tutorial for it?


r/UnityHelp • • Jul 27 '22

Solved Need help making shotgun knockback (if shotgun is fired then knock the player in the other direction)

3 Upvotes

Im really new to unity and the code right now, looks like this:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using EZCameraShake;

public class shoot : MonoBehaviour

{

public Transform Gun;

public Animator Gunanimator;

Vector2 direction;

public GameObject Bullet;

public float Bulletspeed;

public Transform shootpoint;

void Start()

{

}

void Update()

{

Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

direction = mousePos - (Vector2)Gun.position;

Facemouse();

if (Input.GetMouseButtonDown(0))

{

Shoot();

}

}

void Facemouse()

{

Gun.transform.right = direction;

}

public void Shoot()

{

GameObject Bulletins = Instantiate(Bullet, shootpoint.position, shootpoint.rotation);

Bulletins.GetComponent<Rigidbody2D>().AddForce(Bulletins.transform.right * Bulletspeed);

Gunanimator.SetTrigger("Shoot");

CameraShaker.Instance.ShakeOnce(2f,1.6f,0.5f,0.7f);

Destroy(Bulletins, 10);

}

}

I would love some help! tysm!


r/UnityHelp • • Jul 23 '22

PROGRAMMING How can I set my InputAction to NOT be read only? I'm new to unity and can't find a solution.

Post image
3 Upvotes

r/UnityHelp • • Jul 05 '22

blender shape keys not showing up in unity

3 Upvotes

Greetings, internet,

A while ago, I made a model for one of my bosses in blender. In blender, everything is great. My model consists of different meshes: A robe and a head, as well as two eyeballs. The head has shape keys so I can easily change the facial expression.

I exported the model as an .fbx, imported it to unity, but my shape keys are not showing up (the head has no skinned mesh renderer component, only a regular mesh renderer. Changing the mesh renderer to a skinned mesh renderer results in unity telling me that shape keys are missing)

Does anyone know what I'm doing wrong? It's not terribly important, as I could get away with just making him look grumpy by default, but that takes away the charme, so I really hope someone can help me. If there's anything else you need to know, i'll try to answer any questions as soon as possible


r/UnityHelp • • Jun 27 '22

Anyone want to team up to make this whole thing easier? -- See comment

Thumbnail
gallery
3 Upvotes

r/UnityHelp • • Jun 20 '22

PROGRAMMING How do I make a button change the index of an array in my script?

3 Upvotes

Noob here. I am very unsure what's wrong with my code. I'm trying to make it so that the array stops at lines[2]. Then, when a button is pressed, I want it to change the index to an integer that is +1 higher than it originally was or +2 higher if a different button is pressed. I have already kind of figured out how to make it stop at lines[2], but it keeps giving me the IndexOutOfRangeException, even though it functions as intended when I actually play the game. Any help or point in the right direction would be greatly appreciated. Thank you!

using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using TMPro;
 
 public class Dialogue : MonoBehaviour
 {
     public TextMeshProUGUI textComponent;
     public string[] lines;
     public float textSpeed;
 
     private int index;
 
     void Start()
     {
         textComponent.text = string.Empty;
         StartDialogue();
     }
     void Update()
     {
         if (Input.GetMouseButtonDown(0))
         {
                 if (textComponent.text == lines[index])
                 {
                     NextLine();
                 }
                 else
                 {
                     StopAllCoroutines();
                     textComponent.text = lines[index];
                 }
         }
         if (textComponent.text == lines[2]) //pause
         {
             index--;
         }
     }
 
     void StartDialogue()
     {
         index = 0;
         StartCoroutine(TypeLine());
     }
 
     IEnumerator TypeLine()
     {
         foreach (char c in lines[index].ToCharArray())
         {
             textComponent.text += c;
             yield return new WaitForSeconds(textSpeed);
         }
     }
     void NextLine()
     {
         if (index < lines.Length - 1)
         {
             index++;
             textComponent.text = string.Empty;
             StartCoroutine(TypeLine());
         }
         else
         {
             gameObject.SetActive(false);
         }
     }
     public void choice1()
     {
         index = 3;
     }
     public void choice2()
     {
         index = 4;
     }
 }
 //built with "5 Minute DIALOGUE SYSTEM in UNITY Tutorial" by BMo

NOTE: I made the same post in the Unity Help Room but no one responded so I am posting it here.


r/UnityHelp • • Jun 15 '22

PROGRAMMING I'm trying to load a scene after a video is done playing. What am I doing wrong? Any help would be appreciated.

Post image
3 Upvotes

r/UnityHelp • • Jun 13 '22

PROGRAMMING I'm using Visual Studio 2022, and I'm getting the errors below. What am I doing wrong? Any help would be appreciated.

Post image
3 Upvotes

r/UnityHelp • • Jun 07 '22

"Cannot Implicitly Convert Type Bool To Float"

3 Upvotes

Hi, I'm pretty new to coding c# and was watching this tutorial on camera and rigidbody movement. Here's the link https://www.youtube.com/watch?v=f473C43s8nE&t=180s. I was at the part where he showed me how to stop drag and stuff. the timestamp is 5:16. I did exactly what he did. But he doesn't get the error, I don't understand this and if anyone could help me it would mean a lot. Heres my code

` using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Movement : MonoBehaviour

{

[Header("Movement")]

public float moveSpeed;

[Header("GroundCheck")]

public float groundDrag;

// drag stuff

public float playerHeight;

public LayerMask whatIsGround;

bool grounded;

// drag stuff

public Transform orientation;

float horizontalInput;

float verticleInput;

Vector3 moveDirection;

Rigidbody rb;

private void Start()

{

rb = GetComponent<Rigidbody>();

rb.freezeRotation = true;

}

private void Update()

{

// ground check

grounded = Physics.Raycast(transform.position, Vector3.down, playerHeight * 0.5f + 0.2f, whatIsGround);

// ground check

MyInput();

if (grounded)

rb.drag = grounded;

else

rb.drag = 0;

}

private void FixedUpdate()

{

movePlayer();

}

private void MyInput()

{

horizontalInput = Input.GetAxisRaw("Horizontal");

verticleInput = Input.GetAxisRaw("Vertical");

}

private void movePlayer()

{

moveDirection = orientation.forward * verticleInput + orientation.right * horizontalInput;

rb.AddForce(moveDirection.normalized * moveSpeed * 10f, ForceMode.Force);

}

} `


r/UnityHelp • • May 13 '22

PROGRAMMING Skinnedmesh vertexbuffer output not correct? Driving me nuts. In the gif, red wire mesh is raw vertexbuffer output, and everything else is default unity output, what am I missing to make them align? It’s like the hip doesn’t move in vertexbuffer output, but I can’t figure out the correct transform

3 Upvotes

r/UnityHelp • • May 01 '22

error code that is consfusing me

Post image
3 Upvotes

r/UnityHelp • • Apr 13 '22

UNITY Question about slot machine asset.

3 Upvotes

If you have used the Slot-Machine 2D asset from Beavy. Please message me! I am struggling with getting it to start. I import the prefab into my project and then press play but cannot interact with it like in the demo video.

https://beavystore.com/portfolio/make-a-slot-machine-in-unity-2d/


r/UnityHelp • • Apr 11 '22

PROGRAMMING How to unsub from events with lambdas. All of the forums bring up something called event handler which I do not have. Any help would be great!

Post image
3 Upvotes

r/UnityHelp • • Apr 07 '22

PROGRAMMING Working on a FPS Controller and a Stamina Bar

3 Upvotes
This Script is the Player Controller (This on the Player)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    [SerializeField] Transform playerCamera = null;
    [SerializeField] public float mouseSensitivity = 3.5f;
    [SerializeField] public float walkSpeed = 4f;
    [SerializeField] public float runSpeed = 9.0f;
    [SerializeField] public float returntowalkSpeed = 4f;
    [SerializeField] public float gravity = -13.0f;
    [SerializeField] [Range(0.0f, 0.5f)] float moveSmoothTime = 0.3f;
    [SerializeField] [Range(0.0f, 0.5f)] float mouseSmoothTime = 0.03f;

    [SerializeField] bool lockCursor = true;
    [SerializeField] public bool IsWalking;

    float cameraPitch = 0.0f;
    float velocityY = 0.0f;
    CharacterController controller = null;

    Vector2 currentDir = Vector2.zero;
    Vector2 currentDirVelocity = Vector2.zero;

    Vector2 currentMouseDelta = Vector2.zero;
    Vector2 currentMouseDeltaVelocity = Vector2.zero;

    void Start()
    {
        controller = GetComponent<CharacterController>();
        if (lockCursor)
        {
            Cursor.lockState = CursorLockMode.Locked;
            Cursor.visible = false;
        }
    }

    void Update()
    {
        UpdateMouseLook();
        UpdateMovement();
    }

    void UpdateMouseLook()
    {
        Vector2 targetMouseDelta = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));

        currentMouseDelta = Vector2.SmoothDamp(currentMouseDelta, targetMouseDelta, ref currentMouseDeltaVelocity, mouseSmoothTime);

        cameraPitch -= currentMouseDelta.y * mouseSensitivity;
        cameraPitch = Mathf.Clamp(cameraPitch, -90.0f, 90.0f);

        playerCamera.localEulerAngles = Vector3.right * cameraPitch;
        transform.Rotate(Vector3.up * currentMouseDelta.x * mouseSensitivity);
    }

    void UpdateMovement()
    {
        Vector2 targetDir = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
        targetDir.Normalize();

        currentDir = Vector2.SmoothDamp(currentDir, targetDir, ref currentDirVelocity, moveSmoothTime);

        if (controller.isGrounded)
            velocityY = 0.0f;

        velocityY += gravity * Time.deltaTime;

        Vector3 velocity = (transform.forward * currentDir.y + transform.right * currentDir.x) * walkSpeed + Vector3.up * velocityY;

        controller.Move(velocity * Time.deltaTime);

        {

            //...

            if (Input.GetKeyDown(KeyCode.LeftShift))
            {
                // Set current speed to run if shift is down
                walkSpeed = runSpeed;
                IsWalking = false;
            }
            else if (Input.GetKeyUp(KeyCode.LeftShift))
            {
                // Otherwise set current speed to walking speed
                walkSpeed = returntowalkSpeed;
                IsWalking = true;
            }
        }


    }
}


This Script is for Stamina (This on a UI Slider)

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

public class Stamina : MonoBehaviour
{
    PlayerController playerController;
    [SerializeField] GameObject player;

    public Slider staminaBar;

    private int maxStamina = 100;
    private float currentStamina;
    private float maxValue = 100;

    private WaitForSeconds regenTick = new WaitForSeconds(0.1f);
    private Coroutine regen;

    public static Stamina instance;


    //This Awake stuff will deal with Stamina
    void Awake()
    {
        playerController = player.GetComponent<PlayerController>();
        instance = this;
    }

    // Start is called before the first frame update
    void Start()
    {
        currentStamina = maxStamina;
        instance.maxValue = maxStamina;
        staminaBar.value = maxStamina;
    }

    // Update is called once per frame
    void Update()
    {
        if(currentStamina > 10)
        {
            if (Input.GetKey(KeyCode.LeftShift))
            {
                UseStamina(0.30f);
            }
            playerController.runSpeed = 9f;
            playerController.walkSpeed = 4f;
            playerController.returntowalkSpeed = 4f;
        }

        else if (currentStamina <= 20)
        {
            playerController.IsWalking = true;
            staminaBar.value = currentStamina;
            playerController.runSpeed = 4f;
            playerController.walkSpeed = 4f;
            playerController.returntowalkSpeed = 4f;
        }
    }

    public void UseStamina(float amount)
    {
        if(currentStamina - amount >= 0)
        {
            currentStamina -= amount;
            staminaBar.value = currentStamina;

            if (regen != null)
            {
                StopCoroutine(regen);
            }

            regen = StartCoroutine("RegenStamina");
        }

    }

    private IEnumerator RegenStamina()
    {
        yield return new WaitForSeconds(2);

        while (currentStamina < maxStamina)
        {
            currentStamina += maxStamina / 100;
            staminaBar.value = currentStamina;
            yield return regenTick;
        }
    }
}

Ok so here is my issue I have made these two scripts in order to make a FPS Game with a Stamina mechanic and everything is working out well except for the fact that my player doesn't start running when I press LShift. However there isn't any errors according to the Unity Editor and it goes away when the Stamina script gets turned off.

I will like some help in trying to figure out why the Player isn't speeding up?


r/UnityHelp • • Mar 12 '22

UNITY Unity Hub Redirect To Blank web page

Post image
3 Upvotes

r/UnityHelp • • Mar 03 '22

PROGRAMMING Issue with code. Basically I want there to be a value that represents the chosen objects localScale x and y value.

3 Upvotes

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class circleScale : MonoBehaviour

{

[SerializeField]

private Transform transformScale;

private void Start()

{

private float ratioX = transformScale.localScale.x;

}

}

This says that ratioX is reffering to a non static variable or something.

Also it says that it is missing an end bracket...


r/UnityHelp • • Feb 24 '22

Projecting procedural attack telegraph decal on surface

3 Upvotes

I'm creating an isometric 3d brawler. I'm trying to draw a telegraphing "attack area" effect on the ground (Meshes, not Unity terrain), from an arbitrary polygon (including curved lines.), based on Vector3 points.

I figure I need to use the Unity decal system, but I'm not sure how to generate the area texture procedurally, especially since it needs to match points in 3d space. Here are a few examples of the effect I'm looking for.

/preview/external-pre/hHPH8hxnCOvrj8110ahUH0kDPVfw0_pUPSYk8UrKyg0.jpg?auto=webp&s=bb4d8276df0df9fbc79b3d48cb2ee3452e2ad701


r/UnityHelp • • Feb 18 '22

Animation Help

3 Upvotes

I have an idle and moving animation for the top set of teeth. In the animation controller it is set so the default animation is the idle animation. Tho when I start the game is automatically plays the moving animation no matter what. I dont know how to solve this.