Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

unity interfaces

// When you use an interface, you can use two diferent objects to perform one 
// action in common that executes diferently in each of theme.

Interface IDrivable {
	void Drive(); //just the sentence
    //....
}

// Examples of uses:

class Car1 : IDrivable
{ 
	void Drive() {
	//actions to drive the first Car
	}
}

class Car2 : IDrivable
{
	void Drive() {
	//actions to drive the second Car
	}
}

// In this example Car1 and Car2 are diferent classes and each of theme
// drives diferently, but can be used in something like this:

public IDrivable CarToDrive;
CarToDrive.Drive() // this executes Drive() in the selected car, no methers
					// what car is.
Comment

unity interface

//This code is in a seperate class

public interface ISomethingable<T>
{
	
	int RandomVar {get; set} // This is not needed, you can use any variable
    
	// need to be present in classes, which use this interface
    void Function(T Arg);

}

//This Code is in a seperate class

public class Thingy : MonoBehaviour, ISomethingable<T>
{

	public void Function(int Arg)
    {
    
    	Debug.Log(Arg);
    
    }

}

Comment

PREVIOUS NEXT
Code Example
Csharp :: long string c# 
Csharp :: C# assigning image location 
Csharp :: count number of specific characters in string c# 
Csharp :: unity GetNestedComponentsInChildren 
Csharp :: c# string verbatim 
Csharp :: c# new object 
Csharp :: convert json date to datetime c# 
Csharp :: Using Linq to get the last N elements of a collection? C# 
Csharp :: why to make private fields readonly in c# 
Csharp :: catch multiple exception c# 
Csharp :: c# C# read text from a certain line number from string 
Csharp :: c# array lenght 
Csharp :: *ngif vs ngif 
Csharp :: how to call a method from a class c# 
Csharp :: unity read console log 
Csharp :: unity trygetcomponent 
Csharp :: how to get the dynamic year for your web app in mvc 
Csharp :: AuthenticationTicket authenticationProperties C# .net 
Csharp :: if session is not active then redirect to login page mvc.net 
Csharp :: c# compare months 
Csharp :: deferred rendering unity 
Csharp :: blazor editform empty 
Csharp :: mesh decimate pyvista 
Csharp :: c# base vs this 
Csharp :: Bitwise Left Shift C# 
Csharp :: devexpress aspxdatagridview set VerticalScrollableHeight in codebehind 
Csharp :: unity update not called 
Csharp :: Deserialize a Dictionary 
Csharp :: how long dose it take for formate a currupt USB? 
Csharp :: convert iqueryable to list c# 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =