I am developing a scene in Unity that will feature augmented reality. I would like my 3D object to be loaded from an external server. I was following a youtube tutorial on how to do that and he uses this script:
using UnityEngine;
using System.Collections;
using UnityEditor;
public class CreateAssetBundles : MonoBehaviour
{
[MenuItem("Assets/Build AssetBundles")]
static void BuildAllAssetBundles()
{
BuildPipeline.BuildAssetBundles("Assets/AssetBundles");
}
}
However, BuildPipeline.BuildAssetBundles is said to be deprecated. There are added parameters which I have no idea what to put. This is my first time using Build Pipeline. How do I fix this? I tried asking in unityanswers but sadly noone was able to help me so I'm hoping that someone can help me here.
Related
I have made a unity physics based Jetski Game and am having trouble with getting it onto my Oculus Quest 2 and it actually working. For me I am stuck in a place that doesn't have good enough Wi-Fi to run air link and don't have the cable link. These has caused me to build it straight onto the headset itself. When running it on the headset the three loading dots would start playing its animation and never stop, but when you clicked the oculus button it would come up with the error "JetSki has stopped working." (JetSki is the game name.)
These are the tools that I am using and other information that may be needed:
How I set up the keystore: https://www.youtube.com/watch?v=qFS77pQ2VaQ
How I set up VR in unity: https://www.youtube.com/watch?v=HhtTtvBF5bI and https://www.youtube.com/watch?v=8PCNNro7Rt0
How I am getting the inputs:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class InteractionInput : MonoBehaviour
{
public InputActionProperty triggerPress, triggerBool;
public InputActionProperty gripPress, gripBool;
[HideInInspector]
public float gripValue, triggerValue;
[HideInInspector]
public bool gripPressed, triggerPressed;
void Update()
{
triggerValue = triggerPress.action.ReadValue<float>();
triggerPressed = triggerBool.action.ReadValue<bool>();
gripValue = gripPress.action.ReadValue<float>();
gripPressed = gripBool.action.ReadValue<bool>();
}
}
How I am building the project:
I have searched everywhere and all I can find are random threads on stack overflow and unity forums. Yet these are talking about if it crashes when connected to a pc and none of those have helped. There is no one that I have found that is in this exact problem. After this searching I also tried to use the Side Quest to upload the .apk to my headset but I got another error: self signed certificate in certificate chain. Any tips or solutions would be greatly appreciated.
Thanks
Stan :)
I am completely new to Unity and all other answers I've found for this go over my head.
So far I've run everything from the same script, which is getting very big and messy. Therefore I am trying to learn how to call methods from other scripts.
I have a dropdown menu with the code in one script and I'm trying to call that code from another.
ScriptA:
using UnityEngine;
public class ChoseLanguage: MonoBehaviour
{
public TMPro.TMP_Dropdown myDrop;
DisplayController displayController;
public void DropdownChooseLanguage()
{
if (myDrop.value == 1)
PlayerPrefs.SetString("chosenLanguage", "Spanish");
if (myDrop.value == 2)
PlayerPrefs.SetString("chosenLanguage", "Japanese");
if (myDrop.value == 3)
PlayerPrefs.SetString("chosenLanguage", "Korean");
if (myDrop.value == 4)
PlayerPrefs.SetString("chosenLanguage", "Icelandic");
Debug.Log(PlayerPrefs.GetString("chosenLanguage"));
displayController.DropdownSetLanguage();
}
}
The selection code works by itself, and the debug.Log shows that the chosen language is being saved correctly to PlayerPrefs.
The error comes when it tries to read the "displayController.DropdownChooseLanguage();" line. (Line 28)
Unity gives this error:
NullReferenceException: Object reference not set to an instance of an object
ChoseLanguage.DropdownChooseLanguage () (at Assets/Scripts/ChoseLanguage.cs:28)
Script B
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Linq;
using TMPro;
public class DisplayController : MonoBehaviour
{
...
public void DropdownSetLanguage()
{
SetFileName();
setLanguage.gameObject.SetActive(false);
Start();
}
...
}
Earlier, the exact same code from Script A was placed in ScriptB and all the code worked as it should.
This is a very noob question but I have simply just never been able to understand how exactly to access other scripts correctly.
Any help will be greatly appreciated.
Thanks.
EDIT:
I found a solution to this but I'll keep the question up in case other beginners have the same problem or if anyone has a better solution.
I made the DisplayController displayController; into public DisplayController displayController; and then dragged the gameobject with the displaycontroller script attached into the slot for it.
DropdownSetLanguage is public and it seems you think you can access it by
creating a DisplayController object named displayController.
It is ok
about to access a class but, displayController should be null in this state.
Because you have to assign an initial DisplayController to displayController
in your first code.
You can add public or [Serializable] tag in front of
DisplayController displayController; in your first code then, you can add
a GameObject which has a DisplayController script in it in Unity editor.
accessibility
I just started learning c# for unity today and at my 3rd line of code I run into a problem:
My VSCode doesn't "recognize" the GameObject variable. The autocomplete menu doesnt show it and if I hard-write it, it doesnt get coloured.
Im following this tutorial and I dont wanna keep going without solving this.
Its worth clarifying that I didnt install anything other than VSCode and Unity 2019.3.2 and maybe I need a some extension?
Here's the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
public int health = 5;
public float fhealth = 5.0;
public GameObject player;
}
Visual Studio Code normally doesnt autocomplete Classes if not installed with Unity Package Manager. So, if you dont have any compiler errors you could just continue without autocomplete.
As the title says, I'm trying to set up a UI slider so the player can adjust some of the post processing settings (specifically the exposure and temperature) while the game is running.
To bring you up to speed:
I'm using version one of the post processing stack, as found here:
https://assetstore.unity.com/packages/essentials/post-processing-stack-83912
I'm very new to C#; I'm at the "Frankenstein" stage of learning how to code (following tutorials and modifying what works until it breaks or does what I'm trying to accomplish).
I figure my best shot is to try to adapt what I learned from this tutorial on creating an audio volume slider: https://www.youtube.com/watch?v=YOaYQrN1oYQ&t=122s
This is the code I've cobbled together so far:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BrightnessSlider : MonoBehaviour {
public void SetBrightness (float brightness)
{
Debug.Log(brightness);
}
}
Specific issues I'm having at specific points in the tutorial:
2:07 For the function of the slider, the tutorial sets up a dynamic float that matches the custom method (SetVolume) they specify. When I try setting up my own function with a custom method (SetBrightness), I can't find it. I'm also not sure if I need to set a different object instead of the canvas for this step.
3:47 In the tutorial they expose a parameter for the volume so that it can be manipulated through script, but I don't know what the equivalent of that would be for post processing.
For the record, I was able to follow this tutorial to create my own audio slider and got it working with no problems.
One last thing: I opened up the script for the post processing profile and found the variable type I think I'd need or would at least be somewhat relevant: ColorGradingModel, but I honestly have no idea what to do with this information.
Update July 09, 2018
I've since been looking over #Nol's code and had someone else look at it and help me out with it. At the moment, the slider's functionality(not sure if that's the correct terminology but that's what I've been sticking with) is set up through the On Value Changed field in the inspector , but it's not actually driving/changing the brightness values. I had someone else (who's far more qualified than I am) look at it with me. It seems like it should work the way they've set it up, but something is getting lost in translation between the method and the slider.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.PostProcessing;
using UnityEngine.UI;
public class BrightnessSlider : MonoBehaviour
{
public Slider slider;
public PostProcessingProfile Default;
private ColorGradingModel cgm;
private void Start()
{
//I haven't been able to get this to not return some sort of error,
//and I'm not even sure of its usefulness.
//I've been keeping it commented out for the most part.
Default.profile.TryGetSettings(out cgm);
}
public void SetBrightness(float brightness)
{
ColorGradingModel.Settings settings = cgm.settings;
settings.basic.postExposure = brightness;
cgm.settings = settings;
Debug.Log("Brightness is: " + brightness); //For testing purposes
}
}
It seems like you have the core of what you need to know for changing your settings down. That's good.
You'll need a few simple changes:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering.PostProcessing; //How you'll access PPV (Post Processing Volume) models and settings
public class BrightnessSlider : MonoBehaviour {
PostProcessingVolume ppv; //You can make this public to set in inspector
ColorGradingModel cgm; //can use ppv.profile.TryGetSettings(out cgm) in Start()
public void SetBrightness (float brightness)
{
cg.[setting you want to change].value = brightness;
}
}
So apparently i suck at listening at my university, because i can't figure this out, not even with google...
How do you create a scriptable object in the editor? I have the project open, it looks like this:
Click the Create button as if you wanted to create a folder or C# script or anything.
Select the ScriptableObject from the popup menu.
Get this panel and finalize the object after selecting the script for it.
The problem is: i don't have the ScriptableObject button. I have a script that is a scriptable object (to make sure i even copied the one from the project of the university). I restarted Unity, i checked if there were any packages installed (there werent) and i googled quite a bit. But i just can't seem to get this working...
Is there anything i have to install or add first?
Thanks in advance!
You need another script to add the button which will create an instance from that scriptable object. something like that
using UnityEngine;
using System.Collections;
using UnityEditor;
public class MakeScriptableObject {
[MenuItem("Assets/Create/My Scriptable Object")]
public static void CreateMyAsset()
{
MyScriptableObjectClass asset = ScriptableObject.CreateInstance<MyScriptableObjectClass>();
AssetDatabase.CreateAsset(asset, "Assets/NewScripableObject.asset");
AssetDatabase.SaveAssets();
EditorUtility.FocusProjectWindow();
Selection.activeObject = asset;
}
}
You can check this Introduction to Scriptable Objects tutorial on unity website.
I can't comment so just place it like answer:
Don't forget to use UnityEditor.AssetDatabase.GenerateUniqueAssetPath coz simple AssetDatabase.CreateAsset can erase your data:
using UnityEngine;
using System.Collections;
using UnityEditor;
public class MakeScriptableObject
{
[MenuItem("Assets/Create/My Scriptable Object")]
public static void CreateMyAsset()
{
MyScriptableObjectClass asset = ScriptableObject.CreateInstance<MyScriptableObjectClass>();
string name = UnityEditor.AssetDatabase.GenerateUniqueAssetPath("Assets/NewScripableObject.asset");
AssetDatabase.CreateAsset(asset, name);
AssetDatabase.SaveAssets();
EditorUtility.FocusProjectWindow();
Selection.activeObject = asset;
}
}