How to see which mouse button was pressed (Unity Input System)

I have switched my game to use the new Unity Input System, and I want to know which mouse button was pressed when an action is called.

Here’s how it’s set up: Input System

Whenever one of these three mouse buttons are pressed, the MouseButtonClicked action will fire. I want to somehow know which one of these buttons was pressed from this single action, rather than making 3 seperate actions for 3 seperate mouse buttons.

I have tried reading the values from InputAction.CallbackContext context but I can’t seem to get a proper value from the mouse button which was pressed.

How can I do this?

How can I destroy all enemies with the click of a button?

I want to add a booster. For example, when the score is 50, I draw a Texture. When the user clicks on this Texture, I want the enemies on the screen to disappear and return to the original speed. I have completed the drawing process. How can I get this new texture to destroy all enemies on the screen when clicked? Should I do it under public boolean touchDown?

public class Game extends ApplicationAdapter implements InputProcessor { SpriteBatch batch;  Texture background;   Texture health;  Texture virus;  Texture bigvirus;  Texture medicine;  Texture radiation; Texture booster;  //new things to try private Vector2 vector2; Sprite boosterSprite;      BitmapFont font; FreeTypeFontGenerator fontGen;  Random random = new Random(); Array<Items> itemsArray = new Array<Items>();             int lives = 0; int score = 0;  float genCounter = 0; private final float startGenSpeed = 1.1f;  //başlatma hızı float genSpeed = startGenSpeed;   private double currentTime; private double gameOverTime = -1.0f;      @Override public void create () {     batch = new SpriteBatch();     background = new Texture("backgroundlungs.png");     health = new Texture("health.png");     virus = new Texture("virus.png");     bigvirus = new Texture("bigvirus.png");     medicine = new Texture("medicine.png");     radiation = new Texture("radiation.png");     booster = new Texture("booster.png");        vector2=new Vector2();     boosterSprite=new Sprite(booster);     boosterSprite.setPosition((*9,( 10)*8);         Items.radius = Math.max(, / 13f;   //resim boyutları buradan ayarlanıyor     Gdx.input.setInputProcessor(this);      fontGen = new FreeTypeFontGenerator(Gdx.files.internal("robotobold.ttf"));     FreeTypeFontGenerator.FreeTypeFontParameter params = new FreeTypeFontGenerator.FreeTypeFontParameter();     params.color = Color.WHITE;     params.size = 50;     params.characters = "0123456789 ScreCutoplay:.+-";     font = fontGen.generateFont(params);  }    @Override public void render () {     batch.begin();     batch.draw(background,0,0,,;       double newTime = TimeUtils.millis() / 1000.0;     System.out.println("newTime: " + newTime);     double frameTime = Math.min(newTime - currentTime,0.3);     System.out.println("frameTime: " + frameTime);     float deltaTime = (float) frameTime;     System.out.println("deltaTime: " + deltaTime);     currentTime = newTime;       if (lives <= 0 && gameOverTime == 0f) {         //gameo         gameOverTime = currentTime;     }      if (lives > 0 ) {         //game mode          genSpeed -= deltaTime * 0.0075f;    //item yoğunluğunu buradan ayarliyoruz.          System.out.println("genspeed: " + genSpeed);         System.out.println("gencounter: " + genCounter);          if (genCounter <= 0f) {             genCounter = genSpeed;             addItem();         } else {             genCounter -= deltaTime;         }          for (int i = 0; i< lives; i++) {             batch.draw(health,i*30f + 20f,,25f,25f);         }          for (Items items : itemsArray) {             items.update(deltaTime);              switch (items.type) { //dikdörtgen sıkıntı yapabilir.                 case REGULAR:                     batch.draw(virus,items.getPos().x, items.getPos().y, Items.radius,Items.radius);                     break;                 case EXTRA:                     batch.draw(bigvirus,items.getPos().x, items.getPos().y, Items.radius,Items.radius);                     break;                 case ENEMY:                     batch.draw(radiation,items.getPos().x, items.getPos().y, Items.radius,Items.radius);                     break;                 case LIFE:                     batch.draw(medicine,items.getPos().x, items.getPos().y, Items.radius,Items.radius);                     break;               }               if ( lives > 0 && score >= 10 ) {                  boosterSprite.draw(batch);              }                       boolean holdives = false;         Array<Items> toRemove = new Array<Items>();         for (Items items: itemsArray) {             if (items.outOfScreen()) {                 toRemove.add(items);                  if ( && items.type == REGULAR) {                     lives--;                     holdives = true;                     break;                 }              }         }          if (holdives) {             for (Items f : itemsArray) {        = false;             }         }          for (Items f : toRemove) {             itemsArray.removeValue(f,true);         }        }        font.draw(batch,"Score: " + score, 40,50);     if (lives <= 0) {         font.draw(batch,"Cut to play",*0.43f,*0.5f);     }       batch.end(); }  private  void addItem() {     float pos = random.nextFloat() * Math.max(,;      Items item = new Items(new Vector2(pos,-Items.radius),new Vector2(( * 0.5f - pos) * 0.3f + (random.nextFloat() - 0.5f),*0.5f));      float type = random.nextFloat();     if (type > 0.98) {         item.type = Items.Type.LIFE;     }else if (type > 0.88) {         item.type = Items.Type.EXTRA;     }else if (type > 0.809) {         item.type = Items.Type.ENEMY;       }       itemsArray.add(item);      }      @Override public void dispose () {     batch.dispose();     font.dispose();     fontGen.dispose();   }  @Override public boolean keyDown(int keycode) {     return false; }  @Override public boolean keyUp(int keycode) {     return false; }  @Override public boolean keyTyped(char character) {     return false; }    @Override public boolean touchDown(int screenX, int screenY, int pointer, int button) {           return false;  }   @Override public boolean touchUp(int screenX, int screenY, int pointer, int button) {       return false; }  @Override public boolean touchDragged(int screenX, int screenY, int pointer) {         if (lives <= 0  && currentTime - gameOverTime > 2f ) {         //menu mode          gameOverTime = 0f;         score = 0;         lives = 4;         genSpeed = startGenSpeed;         itemsArray.clear();          }else {         //game mode          Array<Items> toRemove = new Array<Items>();         Vector2 pos = new Vector2(screenX, - screenY);         int plusScore =0;         for (Items f: itemsArray) {              System.out.println("distance: " + pos.dst2(f.pos));             System.out.println("distance: " + f.clicked(pos));             System.out.println("distance: "+ Items.radius * Items.radius + 1);                if (f.clicked(pos)) {                 toRemove.add(f);                  switch (f.type) {                     case REGULAR:                         plusScore++;                         break;                     case EXTRA:                         plusScore+=2;                         score++;                         break;                     case ENEMY:                         lives--;                         break;                     case LIFE:                         lives++;                         break;                   }             }         }            score += plusScore * plusScore;          for (Items f : toRemove) {             itemsArray.removeValue(f,true);          }           }      return false;      }    @Override public boolean mouseMoved(int screenX, int screenY) {     return false; }  @Override public boolean scrolled(float amountX, float amountY) {     return false; } 


public class Items {

public static float radius = 60f; Vector2 vector2; public static int boostX = / 10; public static int boostY= ( 10)*9;   public enum Type {     REGULAR, EXTRA, ENEMY, LIFE, BOOSTER }  Type type; Vector2 pos,velocity;    public boolean living =true;    Items (Vector2 pos, Vector2 velocity) {     this.pos = pos;       this.velocity = velocity;      type = Type.REGULAR;  }   public boolean clicked(Vector2 click) {     if (pos.dst2(click) <= radius * radius + 1) {         return true;      }      return false; }  public final Vector2 getPos() {     return pos; }  public boolean outOfScreen() {     return (pos.y < -2f * radius); }  public void update(float dt) {     velocity.y -= dt * ( * 0.2f);     velocity.x -= dt * Math.signum(velocity.x) * 4f;       pos.mulAdd(velocity,dt); } 


Hot to generate shortcode with TinyMCE custom button in WP 5.x?

I’ve created custom shortcode for CTA button:

function cta_shortcode_function( $  atts ) {          $  a = shortcode_atts( array(         'url' => '#',         'text' => 'cta button',         'icon' => '<i class="far fa-caret-square-right"></i>',         'target' => '_blank',         'align' => 'center',      ), $  atts );      echo     '<div class="l-cta '.$  a['align'].'">         <a class="c-cta " href="'.$  a['url'].'" target="'.$  a['target'].'">';         if ( 'before' == get_theme_mod('cta_general_icon_position', true)) {             echo             '<span class="e-cta__icon e-cta__icon--before">                 '.$  a['icon'].'             </span>';         }         echo '<div class="e-cta__text">'.$  a['text'].'</div>';         if ( 'after' == get_theme_mod('cta_general_icon_position')) {             echo              '<span class="e-cta__icon e-cta__icon--after">                 '.$  a['icon'].'             </span>';         }         echo         '</a>     </div>'; }  add_shortcode('cta_shortcode', 'cta_shortcode_function'); 

Now I would like to create this shortcode via button in TinyMCE Editor, so what I did is:

/* Custom button in TinyMCE editor */ function mce_cta_button() {     if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) ) {         add_filter( 'mce_external_plugins', 'custom_tinymce_plugin' );         add_filter( 'mce_buttons', 'register_mce_buttons' );     } } add_action('admin_head', 'mce_cta_button');   // Path to the js file with the custom button function function custom_tinymce_plugin( $  plugin_array ) {     $  plugin_array['mce_cta_button'] = get_template_directory_uri() .'/js/tinymce_buttons_cta.js';     return $  plugin_array; }  // New button in the editor function register_mce_buttons( $  buttons ) {     array_push( $  buttons, 'mce_cta_button' );     return $  buttons; } 

and ofc the JS file:

(function () {   tinymce.PluginManager.add('mce_cta_button', function(editor, url) {       editor.addButton('mce_cta_button', {           icon: false,           text: 'CTA button',           onclick: function (e) {      {                   title: "CTA button's things",                   body: [{                       type: 'textbox',                       name: 'Icon from FontAwesome',                       placeholder: 'Copy and paste <i> object from FontAwesome site',                       multiline: true,                       minWidth: 420,                   },                   {                     type: 'listbox',                     name: 'align',                     label: 'CTA align',                     maxWidth: 420,                     values: [                         {                             text: 'Start',                             value: 'start'                         },                         {                             text: 'Cenetr',                             value: 'center'                         },                         {                             text: 'End',                             value: 'end'                         }                     ]},                   {                       type: 'button',                       name: 'link',                       text: 'Insert/Edit link',                       onclick: function( e ) {                           //get the Wordpess' "Insert/edit link" popup window.                           var textareaId = jQuery('.mce-custom-textarea').attr('id');                           wpActiveEditor = true; //we need to override this var as the link dialogue is expecting an actual wp_editor instance                  textareaId ); //open the link popup                           return false;                       },                   }],                   onsubmit: function( e ) {                       editor.insertContent( 'MY SHORTCODE');                   }               });           }       });   }); })(); 

What I don’t know is how to connect my shortcode to this button and why link window doesn’t work correctly (buttons "ok" or "cancel" aren’t working, I can’t close this window and can’t search pages).

Any help?


Player clips into the ground when I press the restart button

The title says it all. I have a subway surfers like game prototype, where I just added a restart button that can reload the scene. However whenever I press restart the charaters gets into a slightly lower position. After a few deaths the player is clipped into the ground and cannot jump at all. I looked up so many similar questions, all about checking colliders and rigidbodies but I personally couldn’t find anything. It also has to do something with my gravity and stuff. Because I have a gravity modifier that if I set to 1, this issue never happens. The problem is, that then the player jumps around like he is on the moon. I also tried an experiment where I started my player from the air, not from the ground. And with every single restart the player fell faster and faster eventually falling trough the ground once again. So something can be with gravity. This is what I have in the character controller. I wasn’t satisfied with my physics and I wanted it to make a bit more interesting.

I tried readding colliders, putting the same scripts on brand new objects, checking on and off rigidbody options.

void Start()     {         playerRb = GetComponent<Rigidbody>();         Physics.gravity *= gravityModifier;     }      // Update is called once per frame     void Update()     {         Vector3 xPos = new Vector3(xRange, 0, 0);         if (Input.GetKeyDown(KeyCode.Space) && isOnGround)         {             playerRb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);             isOnGround = false;         } 

Unity 3D – Why does my button need to be clicked twice to work?

My goal is to go back and forth between a series of animations by clicking left and right arrow UI buttons. I wrote this C# script and the "next" button (which executes AddInt() on click) works as intended, however the "previous" button (which calls ReduceInt() on click), needs to be clicked twice to work. Is this a glitch or is something wrong with my code?

public class update_animator_parameter_int : MonoBehaviour {     Animator gameobject_animator;     public string int_parameter;     public int max_int;     public int current_int=0;      void Start(){         gameobject_animator = GetComponent<Animator>();}      public void AddInt(){           current_int++;           if (current_int > max_int){current_int = 0;}           gameobject_animator.SetInteger(int_parameter, current_int);}       public void ReduceInt(){           current_int--;           if (current_int < 0){current_int = max_int;}           gameobject_animator.SetInteger(int_parameter, current_int);} } 

How do you create a Log In Button? [closed]

I am trying to create a basic chat website similar to FaceBook in the way that people communicate by messages and everyone has a homepage. How do sites create signup and login buttons for such a thing? Is it JavaScript that stores every user ID? Or do they use Python? What is the way to go with this? I am assuming that the open-source code cannot be stored on the website itself which means you need something else like a dictionary in Python.