I have disabled multi touch but still not working unity - c#

I have disabled multitouch but still, when I place second finger on the screen my joystick snaps to the second finger position.
public class GameManager : MonoBehaviour
{
private void Awake()
{
Input.multiTouchEnabled = false;
}
}
I am using variable joystick from free joystick pack.

public class GameManager : MonoBehaviour
{
private void Awake()
{
Input.multiTouchEnabled = false;
}
}
That would work only if the app was installed on the device, it will not work on the editor and not even using Unity remote, since Unity remote streams your game only and passes some parameters while streaming.
For more info about Unity Remote: Unity Manual - Unity Remote

Related

CharacterMovement::CmdFight() called on NetworkCharacterContainer without authority error

I have been creating a multiplayer game using Mirror. I have coded an entire Fight function, and I turned it to a command function since i want it to be run on a server (because I think it's easier to calculate who you shot on server then on a client), but I get an error:
Command Function System.Void CharacterMovement::CmdFight() called on NetworkCharacterContainer(Clone) without authority
(The error on the title appears on host and I don't know why).
Here is the code:
public void HandleFighting()
{
if(Input.GetMouseButtonDown(0))
{
Debug.Log(this);
CmdFight(); //! We want to fight!
}
}
[Command]
private void CmdFight()
{
if (!isLocalPlayer)
{
Debug.LogWarning("Command Function CmdFight() called on CharacterMovement without authority.");
return;
}
//! If we clicked on left mouse button
if (WeaponData != null)
{
RaycastHit raycastHit;
if (Physics.Raycast(CharacterPosition, Input.mousePosition, out raycastHit, WeaponData.Range))
{
//!We hit a player
GameObject ho = raycastHit.collider.gameObject;
Health health;
if (ho.TryGetComponent<Health>(out health))
{
//! We hit a player
health.SubstactHealth(WeaponData.damage);
health.AddEffects(WeaponData.effects);
}
}
}
}
I am spawning player normally and on network server (like this):
public override void OnServerAddPlayer(NetworkConnectionToClient conn)
{
//TODO Read the code and fix it
GameObject Player = Instantiate(playerPrefab,transform.position,transform.rotation); //! create a player
NetworkServer.Spawn(Player);
If anybody can help, please write it down below.
I have asked ChatGP and it told me like 7 steps, i did them all and nothing worked.
Some of these steps were:
Make sure that the object that is calling the CmdFight() function has a NetworkIdentity component. You can add it by clicking on the object in the Unity editor, and then in the "Add Component" menu, searching for "Network Identity".
or
Make sure that the NetworkIdentity component is correctly set up. In the inspector, check that the "Local Player Authority" option is enabled. This option allows the object to execute command functions as a local player object.
or even
Make sure that the object was instantiated using the NetworkServer.Spawn() method or a NetworkIdentity component with the Local Player Authority option selected.

Problem In Animation On Brackeys Tutorial

I've been following Brackeys's tutorial on how to make a video game in Unity3D. Up to now things have been great.
But now when I create a game over screen and animated it, it keeps on looping when it triggers. I've tried turning off loop time and transitioning to an empty state with no exit time. It also doesn't loop the whole thing just around less than half a second.
My EndTrigger script and CompleteLevel script is below. I don't get any debugging errors.
using unityEngine;
public class EndTrigger : MonoBehaviour {
public GameManager gameManager;
void OnTriggerEnter ()
{
gameManager.CompleteLevel();
}
}
My CompleteLevel Script Below
using UnityEngine;
using UnityEngine.SceneManagement;
public class LevelComplete : MonoBehaviour {
public void LoadNextLevel ()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
}
In your project files select the animation file and make sure you've turned off Loop Time. Unity enables it by default.

For some reason GameObject.Find().SetActive(true) doesn't work and I am unsure why

In my game my player has 2 weapons and in this level I want to make it so that once the player runs out of ammo the shotgun deactivates and the axe activates. Both weapons are child's of the player but this script is attached to the player. The shotgun deactivates but the axe doesn't activate and I don't know why. Thanks!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Ammo : MonoBehaviour
{
public int ammo = 165;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(ammo == 0)
{
GameObject.Find("wp_shotgun").SetActive(false);
GameObject.Find("wp_axe").SetActive(true);
}
}
}
Take into account that a GameObject may be inactive because a parent is not active. In that case, calling SetActive will not activate it, but only set the local state of the GameObject, which you can check using GameObject.activeSelf. Unity can then use this state when all parents become active. Check the documentation.
What I would do is check the hierarchy in case there is some gameobject messing with the desired GO activation, and second check if there is any error in the console in case the GameObject.Find() could throw a nullreference exeption.

Unity Script is not running

i am creating all new unity project and added Empty GameObject in to my first Scene, and also created and added script to that object, but when i'm trying to run my scene script dose not showing any output in my console window.
here is my code
using System.Collections;
using UnityEngine;
public class ScriptObject : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Debug.Log("Start method called.");
}
// Update is called once per frame
void Update()
{
Debug.Log("Update method calling.");
}
}
You need to turn on showing of another types of log messages ("Info" messages in your case).
You need to be sure that your button of the console output is enabled. Just try to click on the button.Look at the screenshot

Simple log in unity c# script

It should be simple, but still can't find a straight answer:
How can I log a simple message using C# Unity script?
I tried this:
Debug.Log("Hello Log");
It doesn't work or I'm not looking at the right place.
Debug.Log("Hello Log"); can be found on the Console Tab.
For you to be able to see it:
1.You must put it in a function from a script.
public class Test : MonoBehaviour
{
void Start()
{
Debug.Log("Hello Log");
}
}
2.Script must be attached to a GameObject.
3.Both the script and the GameObject it is attached to must be enabled.
4.Reset the Layout if you can't see the Console tab.
EDIT:
I tested it on Android Device. That's why I didn't see it.
In that case, use Android Monitor from Android Studio to view the log from your Android device.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Simple : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Debug.Log("Attach this script to component and simple message will be there when you start project");
}
// Update is called once per frame
void Update()
{
}
}

Categories

Resources