hi anybody can help my how i can do 1 key two atcion i think if i use mouse 0 attack and i push q change the shield and i use mouse 0 and if i want change back i use q again
Are you asking if while the mouse button is down, to swap back n forth between 2 options?
An if statement with GetMouseButton
inside it: if GetKeyDown
If it’s something else, please explain.
if i getkeydown “q” i can swap 2 option i want attack mouse and defense a have 2 defense option and i have 2 atack and this want i use my english is bad so i want swap 2 option
so once attack (mouse 0 and mouse 1) and i push “q” change defense animation(mouse0 and mouse 1) and again q change back
Yes, sorry I’m having a tough time understanding you.
From your post that came as I was writing…Do you mean this?
bool attackAnimation = true;
void Update() {
if(Input.GetKeyDown(KeyCode.Q)) attackAnimation = !attackAnimation;
if(Input.GetMouseButton(0))
{
if(attackAnimation)
{
// do attack stuff
}
else
{
// do defense stuff
}
}
}
Is that what you meant?
The mouse button(s) will attack or defend based on the bool value. The bool value will change back n forth, based on the key ‘q’ being pressed.
thank you very much this is i think
hi can you help me because this code not working in multiplayer what i need the change ?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class control : NetworkBehaviour
{
static Animator anim;
public float speed = 10.0F;
public float rotationSpeed = 100.0F;
bool attackAnimation = true;
// Use this for initialization
void Start ()
{
if (isLocalPlayer == true)
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update ()
{
if (isLocalPlayer == true)
{
float translation = Input.GetAxis("Vertical") * speed;
float rotation = Input.GetAxis("Horizontal") * rotationSpeed;
translation *= Time.deltaTime;
rotation *= Time.deltaTime;
transform.Translate(0, 0, translation);
transform.Rotate(0, rotation, 0);
//utesek
if (Input.GetKeyDown(KeyCode.Q)) attackAnimation = !attackAnimation;
if (Input.GetButton("jobb"))
{
if (attackAnimation)
{
anim.SetTrigger("jobbos");
}
else
anim.SetTrigger("jobbdef");
}
if (Input.GetButton("bal"))
{
if (attackAnimation)
{
anim.SetTrigger("balos");
}
else
anim.SetTrigger("baldef");
}
//mozgas
if (translation != 0)
{
anim.SetBool("run", true);
anim.SetBool("idle", false);
}
else
{
anim.SetBool("run", false);
anim.SetBool("idle", true);
}
}
}
}