Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

how use 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 :: The entity type has multiple properties with the [Key] attribute. 
Csharp :: how to pass optional guid parameters in c# 
Csharp :: c# remove first three characters from string 
Csharp :: unity get default font 
Csharp :: get list length c# 
Csharp :: declare dictionary c# 
Csharp :: how to know character is a digit or not in c# 
Csharp :: c# foreach object in array json 
Csharp :: how to read particular line of file in c# 
Csharp :: C# using variables inside strings 
Csharp :: how to restart flutter app programmatically 
Csharp :: C# datareadeer return null 
Csharp :: copy class c# 
Csharp :: c# datetime for filename 
Csharp :: hwo to prevent rotation after hitting an object in unity 
Csharp :: convert html to pdf c# 
Csharp :: unity sort a list 
Csharp :: change size of a unity object 
Csharp :: asp.net response.redirect new tab 
Csharp :: how to write coroutine in unity 
Csharp :: input unity 
Csharp :: quotes in string f# 
Csharp :: cause bsod c# 
Csharp :: wpf stackpanel 
Csharp :: unity get pivot position 
Csharp :: c# yield 
Csharp :: carousel asp.net mvc beginner 
Csharp :: c# best way to loop and remove 
Csharp :: ? operator 
Csharp :: c# null conditional operator if statement 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =