Posts

Showing posts with the label Csharp Example

Array Index Of Js Code Example

Example 1: get index of element in array js const beasts = [ 'ant' , 'bison' , 'camel' , 'duck' , 'bison' ] ; console . log ( beasts . indexOf ( 'bison' ) ) ; // expected output: 1 // start from index 2 console . log ( beasts . indexOf ( 'bison' , 2 ) ) ; // expected output: 4 console . log ( beasts . indexOf ( 'giraffe' ) ) ; // expected output: -1 //*** Thanks to MDN Web Docs ***// //https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Array/indexOf Example 2: js array return only certain positions const every_nth = ( arr , nth ) => arr . filter ( ( e , i ) => i % nth == = nth - 1 ) ; console . log ( every_nth ( [ 1 , 2 , 3 , 4 , 5 , 6 ] , 1 ) ) ; console . log ( every_nth ( [ 1 , 2 , 3 , 4 , 5 , 6 ] , 2 ) ) ; console . log ( every_nth ( [ 1 , 2 , 3 , 4 , 5 , 6 ] , 3 ) ) ; console . log ( every_nth ( [ 1 , 2 , 3 , 4 , 5 , 6 ] ,...

Button Onclick Unity Code Example

Example 1: unity assign button onclick public Button yourButton ; void Start ( ) { Button btn = yourButton . GetComponent < Button > ( ) ; //Grabs the button component btn . onClick . AddListener ( TaskOnClick ) ; //Adds a listner on the button } void TaskOnClick ( ) { Debug . Log ( "You have clicked the button!" ) ; } Example 2: how to code button click unity using UnityEngine ; using UnityEngine . UI ; using System . Collections ; public class ClickExample : MonoBehaviour { public Button yourButton ; void Start ( ) { Button btn = yourButton . GetComponent < Button > ( ) ; btn . onClick . AddListener ( TaskOnClick ) ; } void TaskOnClick ( ) { Debug . Log ( "You have clicked the button!" ) ; } } Example 3: unity onclick object void Update ( ) { } void OnMouseDown ( ) { // this object was clicked - do something Destroy ( this . gameObject ...

Check For Collision Unity Code Example

Example 1: unity how to tell when a gameobject is colliding void OnCollisionEnter ( Collision collision ) { //Check for a match with the specified name on any GameObject that collides with your GameObject if ( collision . gameObject . name == "MyGameObjectName" ) { //If the GameObject's name matches the one you suggest, output this message in the console Debug . Log ( "Do something here" ) ; } //Check for a match with the specific tag on any GameObject that collides with your GameObject if ( collision . gameObject . tag == "MyGameObjectTag" ) { //If the GameObject has the same tag as specified, output this message in the console Debug . Log ( "Do something else here" ) ; } } Example 2: check for collision unity c# void OnCollisionEnter ( Collision col ) { } Example 3: how to do collision tag in uni...

Brython Tutorial Code Example

Example 1: python tutorial print ( "Hello, Python!" ) ; Example 2: python tutorial This is a very good free python tutorial : https : / / www . youtube . com / watch ? v = _uQrJ0TkZlc Example 3: python tutorial # printing hello world in python print ( "Hello World" ) # adding 2 numbers num1 = 10 num2 = 20 print ( num1 + num2 )

Add Velocity To Rigidbody Unity Code Example

Example 1: unity how to set rigidbody velocity Vector3 velocity = new Vector3 ( 10f /*x*/ , 10f /*y*/ , 10f /*z*/ ) ; GetComponent < Rigidbody > ( ) . velocity = velocity ; Example 2: rigidbody velocity c# unity //for rigidbody2D GetComponent < Rigidbody2D > ( ) . velocity = new Vector2 ( 40 , 0 ) ;

Bootstrap Success Message Popup Example

Example 1: boootstrap alerts < div class = "alert alert-primary" role = "alert" > This is a primary alert—check it out ! < / div > < div class = "alert alert-secondary" role = "alert" > This is a secondary alert—check it out ! < / div > < div class = "alert alert-success" role = "alert" > This is a success alert—check it out ! < / div > < div class = "alert alert-danger" role = "alert" > This is a danger alert—check it out ! < / div > < div class = "alert alert-warning" role = "alert" > This is a warning alert—check it out ! < / div > < div class = "alert alert-info" role = "alert" > This is a info alert—check it out ! < / div > < div class = "alert alert-light" role = "alert" > This is a light alert—check it out !...

Add Create Prefab At Position Unity Code Example

Example 1: Unity C# instantiate prefab Instantiate ( myPrefab , new Vector3 ( 0 , 0 , 0 ) , Quaternion . identity ) ; Example 2: unity instantiate prefab Instantiate ( cube , Vector3 ( x , y , 0 ) , Quaternion . identity ) ;

Class Object Array Java Code Example

Example 1: array objects java obj array [ ] = new obj [ 10 ] ; for ( int i = 0 ; i < array . length ; i ++ ) { array [ i ] = new obj ( i ) ; } Example 2: array object java class ObjectArray { public static void main ( String args [ ] ) { Account obj [ ] = new Account [ 2 ] ; //obj[0] = new Account(); //obj[1] = new Account(); obj [ 0 ] . setData ( 1 , 2 ) ; obj [ 1 ] . setData ( 3 , 4 ) ; System . out . println ( "For Array Element 0" ) ; obj [ 0 ] . showData ( ) ; System . out . println ( "For Array Element 1" ) ; obj [ 1 ] . showData ( ) ; } } class Account { int a ; int b ; public void setData ( int c , int d ) { a = c ; b = d ; } public void showData ( ) { System . out . println ( "Value of a =" + a ) ; System . out . println ( "Value of b =" + b ) ; } }

Bash Check If File Exists In Directory Code Example

Example 1: check if file exists bash FILE = / etc / resolv . conf if [ - f "$FILE" ] ; then echo "$FILE exists." else echo "$FILE does not exist." fi Example 2: .sh script: check if file exist #!/bin/bash if [ - e x . txt ] then echo "ok" else echo "nok" fi Example 3: .sh script: check if file exist # The most readable option when checking whether a file exist or not is # to use the test command or the old '[' or the new ' [ [ ' in combination # with the if statement. # Any of the snippets below will check whether the /etc/resolv.conf file # exists: FILE = / etc / resolv . conf if test - f "$FILE" ; then echo "$FILE exist" fi # or FILE = / etc / resolv . conf if [ - f "$FILE" ] ; then echo "$FILE exist" fi # or FILE = / etc / resolv . conf if [ [ - f "$FILE" ] ] ; then echo "$FILE exist...

Asp.net Mvc Redirecttoaction With Parameter Code Example

Example 1: redirecttoaction with parameters return RedirectToAction ( "Action" , new { id = 99 } ) ; Example 2: asp.net core redirecttoaction with parameters RedirectToAction ( "Action" , "Controller" , new { id } ) ;

C# Dictionary Get Specific Key Value Code Example

Example: access dic by key c# using System ; using System . Collections . Generic ; class Program { static void Main ( ) { Dictionary < string , int > dictionary = new Dictionary < string , int > ( ) ; dictionary . Add ( "apple" , 1 ) ; dictionary . Add ( "windows" , 5 ) ; // See whether Dictionary contains this string. if ( dictionary . ContainsKey ( "apple" ) ) { int value = dictionary [ "apple" ] ; Console . WriteLine ( value ) ; } // See whether it contains this string. if ( ! dictionary . ContainsKey ( "acorn" ) ) { Console . WriteLine ( false ) ; } } }

Addforce Unity 2d Code Example

Example: how to make rb.addforce 2d public Rigidbody rb ; //make reference in Unity Inspector public float SpeedX = 0.1f ; public float SpeedY = 0.5f ; rb . AddForce ( new Vector2 ( SpeedX , SpeedY ) ) ;

2d Raycast From Mouse Code Example

Example: unity 2d raycast mouse // detect object that was clicked using raycast RaycastHit2D hit = Physics2D . Raycast ( Camera . main . ScreenToWorldPoint ( Input . mousePosition ) , Vector2 . zero ) ; if ( hit . collider != null ) { Debug . Log ( "Target name: " + hit . collider . name ) ; }

Bootstrap 4 Jquery Modal Show Code Example

Example 1: bootstrap modals < div class = "modal" tabindex = "-1" role = "dialog" > < div class = "modal-dialog" role = "document" > < div class = "modal-content" > < div class = "modal-header" > < h5 class = "modal-title" > Modal title < / h5 > < button type = "button" class = "close" data - dismiss = "modal" aria - label = "Close" > < span aria - hidden = "true" > × < / span > < / button > < / div > < div class = "modal-body" > < p > Modal body text goes here . < / p > < / div > < div class = "modal-footer" > < button type = "button" class = "btn btn-primary" > Save changes < / button > < ...

Addcomponent Unity Code Example

Example 1: unity requirecomponent using UnityEngine ; // PlayerScript requires the GameObject to have a Rigidbody component [ RequireComponent ( typeof ( Rigidbody ) ) ] public class PlayerScript : MonoBehaviour { Rigidbody rb ; void Start ( ) { rb = GetComponent < Rigidbody > ( ) ; } void FixedUpdate ( ) { rb . AddForce ( Vector3 . up ) ; } } Example 2: Add component object to gameobject unity //to add a new ridgidbody gameobject . AddComponent < Rigidbody > ( ) ; //to add a new meshCollider gameobject . AddComponent < MeshCollider > ( ) ; //Original answer by MakerBenjammin6, cleanup by me. Example 3: unity add component //Use the AddComponent<T>() Method to add a component to your gameobject GameObject gameObject ; gameObject . AddComponent < BoxCollider > ( ) ; //Component has to be an actual Unity component Example 4: c# addcomponent // Consider an existing GameObject, ...

Bind FiveM Guide Code Example

Example 1: FiveM pc key code // its C# BTW :) // checks if INPUT_CONTEXT has just been released // assumes `using static CitizenFX.Core.API;` if ( IsControlJustReleased ( 1 , 51 ) ) { // run code here } Example 2: FiveM pc key code -- its Lua BTW : ) -- checks if INPUT_CONTEXT has just been released if IsControlJustReleased ( 1 -- [ [ input group ] ] , 51 -- [ [ control index ] ] ) then -- run code here end

Border: InputBorder Properties Flutter Code Example

Example: input border flutter TextField ( decoration : new InputDecoration ( focusedBorder : OutlineInputBorder ( borderSide : BorderSide ( color : Colors . greenAccent , width : 5.0 ) , ) , enabledBorder : OutlineInputBorder ( borderSide : BorderSide ( color : Colors . red , width : 5.0 ) , ) , hintText : 'Mobile Number' , ) , ) ,

C# Unity What Does GetComponent Code Example

Example 1: how to get component in unity c# GetComponent < Rigidbody > ( ) ; //used to find component on character (rigid body can be changed) GameObject . FindGameObjectWithTag ( "player" ) ; //finds any game object in the scene with this tag Example 2: getcomponent c# //First script public class Enemy : MonoBehaviour { public int health = 10 ; public void saySomething ( ) { Debug . Log ( "Hi, i am an enemy." ) ; } } //Second script //There is one thing though, //if the script is located on another gameobject, //which will be most likely, you have to somehow //find that gameobject first. There are many ways of //doing it, via raycast, collision, //trigger, find by tag, find by gameobject etc. //But i will use the simplest way to understand, //that is declaring public GameObject in player script, //which contains Enemy, and later you just drag and drop the //gameobject in the inspector. public class Player : M...

All Keycodes Unity Code Example

Example 1: unity keycode if ( Input . GetKeyDown ( KeyCode . A ) ) { Debug . Log ( "The A key was pressed." ) ; } Example 2: unity getkey keycode Input . GetKey ( KeyCode . Space ) )

C# Datetime Format Yyyymmddhhmm Code Example

Example: C# datetime.now to string only numbers DateTime . Now . ToString ( "yyyyMMddHHmmss" ) ; // case sensitive