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 :: public tmpro text 
Csharp :: new ienumerable 
Csharp :: parent unity 
Csharp :: C# monogodb 
Csharp :: dotnet core 3.1 get the user that just logged in 
Csharp :: NameValueCollection 
Csharp :: timespan to integer c# 
Csharp :: vector3 unity 
Csharp :: toggle unity c# 
Csharp :: if statement c# 
Csharp :: c# remove char from string 
Csharp :: how to get keyboard input in unity 
Csharp :: multiplication of long numbers 
Csharp :: disable button in android studio 
Csharp :: how to print statement in c# 
Csharp :: use slider in unity 
Csharp :: where in used in linq c# 
Csharp :: checking a gamobjects layer 
Csharp :: c# binary search 
Csharp :: convert int32 
Csharp :: check if value in list c# 
Csharp :: c# create excel file 
Csharp :: simple code to call rest api c# 
Csharp :: assembly project name c# .net 
Csharp :: mongodb c# batch find 
Csharp :: replace multiple characters in string c# 
Csharp :: c# split string by index 
Csharp :: static class can have non static member in c# 
Csharp :: c# convert double to string 
Csharp :: unity check if current scene is being unloaded 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =