B
B
Brian May2020-10-20 18:17:43
Unity
Brian May, 2020-10-20 18:17:43

How to get a method from another script in C#?

I created a script which has a Spawn() method; now I need to use this method in another script. I'm quite green in C#, so if you can be more specific

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DiSay, 2020-10-20
@brianmay

First file code:

using System;

namespace Test1
{
    public static class Name
    { 
        public static void Spawn(byte Position)
        { 
            //Код допустим тут
        }
    }
}

Code 2:
using Test1;
using System;

public class Tetsu
{ 
    public void NAmed()
    {
        Name.Spawn(100);
    }
}

This is a small example, not everything is correct here (well, or everything xs)
Everything is clear here. I
'm lazy in more detail, but if something is not clear, I can explain)

W
WasTabon, 2020-10-22
@WasTabon

First code -

public ScriptName scriptName

private void Start()
{
    scriptName.method();
}

Second code (called let's say ScriptName)
public void method()
{
    //код
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question