Hello I will actually keep this short.I butchered this piece of code. I can't find the solutions.
My code
using UnityEngine;
using System.Collections.Generic;
using UnityEngine.UI;
public class Linkbutton : MonoBehaviour{
void Update()
{
if (GameObject.activeSelf)
public void LinkFunc();
{
Application.OpenURL ("https://stolpersteinecoevorden.jimdo.com/stolpersteine/"); running = false;
}
}
}
The errors I'm having
I have been trying stuff for hours without a solution in view.
Thanks in advance
Try this:
public class Linkbutton : MonoBehaviour
{
bool running = true;
void Update()
{
if (this.gameObject.activeSelf)
LinkFunc();
}
public void LinkFunc()
{
Application.OpenURL("https://stolpersteinecoevorden.jimdo.com/stolpersteine/");
running = false;
}
}
Related
I am trying to make a simple inventory in Unity 3D for virtual environment. I am using StemVR plugin, because I have HTC Vive. I was following this tutorial, made for Oculus (https://www.youtube.com/watch?v=gAz_SeDUQBk&t=310s) and now I have to adapt the code for HTC Vive, but I don't know how.
In the slot script I have a problem with this part of the script, where it should release an item after releasing a trigger:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Valve.VR;
public class Slot : MonoBehaviour
{
public GameObject ItemInSlot;
public Image slotImage;
void Start()
{
slotImage = GetComponentInChildren<Image>();
originalColor = slotImage.color;
}
private void OnTriggerStay(Collider other)
{
if (ItemInSlot != null) return;
GameObject obj = other.gameObject;
if (!IsItem(obj)) return;
if (OVRInput.GetUp(OVRInput.Button.SecondaryHandTrigger))
{
InsertItem(obj);
}
}
bool IsItem(GameObject obj)
{
return obj.GetComponent<Item>();
}
void InsertItem(GameObject obj)
{
obj.GetComponent<Rigidbody>().isKinematic = true;
obj.transform.SetParent(gameObject.transform, true);
obj.transform.localPosition = Vector3.zero;
obj.transform.localEulerAngles = obj.GetComponent<Item>().slotRotation;
obj.GetComponent<Item>().inSlot = true;
obj.GetComponent<Item>().currentSlot = this;
ItemInSlot = obj;
}
}
And in Inventory script I have a problem with adapting this part:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Valve.VR;
public class InventoryVR : MonoBehaviour
{
public GameObject Inventory;
public GameObject Anchor;
bool UIActive;
private void Start()
{
Inventory.SetActive(false);
UIActive = false;
}
private void Update()
{
if (OVRInput.GetDown(OVRInput.Button.Four))
{
UIActive = !UIActive;
Inventory.SetActive(UIActive);
}
}
}
What functions can I use to make this applicable for HTC Vive?
i am trying to make a multiplayer game by following a tutorial but i dont know why when i check from which is wrong i'm using photon free i also looked at the other forum but i can't solve
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class Launcher : MonoBehaviourPunCallbacks
{
// Start is called before the first frame update
void Start()
{
Debug.Log("Connecting to Master");
PhotonNetwork.ConnectUsingSettings();
}
public override void OnConnectedToMaster()
{
Debug.Log("Connected to Master");
PhotonNetwork.JoinLobby();
}
public override void OnJoinedLobby()
{
Debug.Log("Joined Lobby");
}
// Update is called once per frame
void Update()
{
}
}
I'm trying to build a Unity game, and keep getting the error:
Assets\charaterselection.cs(34,9): error CS0103: The name 'PrefabUtility' does not exist in the current context
The issue is I imported UnityEditor, I'm not sure what's going on
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.SceneManagement;
public class charaterselection : MonoBehaviour
{
public SpriteRenderer sr;
public List<Sprite> skins = new List<Sprite>();
private int selecectedSkin;
public GameObject player;
public void Next()
{
selecectedSkin=selecectedSkin+1;
if (selecectedSkin== skins.Count)
{
selecectedSkin=0;
}
sr.sprite= skins[selecectedSkin];
}
public void back()
{
selecectedSkin = selecectedSkin - 1;
if (selecectedSkin < 0)
{
selecectedSkin = skins.Count - 1;
}
sr.sprite = skins[selecectedSkin];
}
public void play()
{
PrefabUtility.SaveAsPrefabAsset(player, "Assets/Players/FROGY.prefab");
SceneManager.LoadScene(1);
}
}
Thank you guys for your help, I literately just made a file called "Editor" and it worked.
I am relatively new to Unity and am currently trying to build an multi-user app on Hololens. Currently, I am just trying to get two Hololens to connect over LAN using Unet. When I use one of my Hololens to host the server, my laptop can connect to it during play mode in the Unity editor. However, when I try to use my other Hololens to connect to it, it does not work and I am not sure why. Does anyone else have this problem? And if so, how do you fix it?
Thanks in advance.
Edit: some code
Here's the code for network manager
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
using System;
public class NetworkManager_Custom : NetworkManager
{
public void StartupHost()
{
setPort();
NetworkManager.singleton.StartHost();
}
public void JoinGame()
{
SetIpAddress();
setPort();
NetworkManager.singleton.StartClient();
}
private void SetIpAddress()
{
string Address = "192.168.2.80";
NetworkManager.singleton.networkAddress = Address;
}
private void setPort()
{
NetworkManager.singleton.networkPort = 9001;
}
}
Here's the code for the start-server button
using HoloToolkit.Unity.InputModule;
using UnityEngine;
using UnityEngine.Networking;
public class ok : NetworkBehaviour, IFocusable, IInputClickHandler
{
bool hasFocus;
public NetworkManager_Custom manager;
public void OnFocusEnter()
{
hasFocus = true;
}
public void OnFocusExit()
{
hasFocus = false;
}
public void OnInputClicked(InputClickedEventData eventData)
{
manager.StartupHost();
}
}
Here's the code for joining server as client
using HoloToolkit.Unity.InputModule;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Networking.NetworkSystem;
public class aegf : NetworkBehaviour, IFocusable, IInputClickHandler
{
bool hasFocus;
public NetworkManager_Custom manager;
public void OnFocusEnter()
{
hasFocus = true;
}
public void OnFocusExit()
{
hasFocus = false;
}
public void OnInputClicked(InputClickedEventData eventData)
{
manager.JoinGame();
}
}
It's worth double-checking the capabilties that you've set. Ensure all three of these are selected:
InternetClient
InternetClientServer
PrivateNetworkClientServer
Ref: https://learn.microsoft.com/en-us/uwp/schemas/appxpackage/appxmanifestschema/element-capability
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playercontroler : MonoBehaviour {
public static playercontroler sharedinstance;
void Awake(){
sharedinstance = this;
rigidBody = GetComponent<Rigidbody2D> ();
}
public void KillPlayer(){
GameManager.sharedistance.GameOver ();
animator.SetBool ("isAlive", false);
}
}
and
public class killtriger : MonoBehaviour {
void OnTriggerEnter2D(Collider2D theObject){
if (theObject.tag == "Player") {
playercontroler.sharedinstance.KillPlayer ();
}
}
}
the problem is that unity return:
"playercontroler" doesnt not contain a definition for sharedinstance
what is the problem? thanks
Don't know if that will fix everything, but you should check if playercontroler.sharedinstance have been set before using it.
public class killtriger : MonoBehaviour {
void OnTriggerEnter2D(Collider2D theObject){
if (theObject.tag == "Player" && playercontroler.sharedinstance) {
playercontroler.sharedinstance.KillPlayer ();
}
}
}
Also make sure the variable name is right. You have the variables sharedistance and sharedinstance in your code. They are for different objects, but I imagine they should have the same name.