Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

579
Views
How to use a script to start another script

So, Im pretty new to unity, and c#, and Im trying to make a system where I can attach a script to an object in unity, and then assign a certain script to this object, so when the player interacts with it, it will call a script. so...

here is where i need to be able to put a script:

here is where i need to be able to put a script

and

here is what I have currently:

here is what I have currently

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Not exactly what you want(I think what you want is bad practise or unachievable), but you can obtain same functionality via following steps,

First you need to create prefab which your script attached to it. Here is small tutorial for that. Then you can use following code.

public GameObject myPrefab;

// This script will simply instantiate the Prefab when the game starts.
void Update()
{
    if(Input.GetKeyDown("f")){
    // Instantiate at position (0, 0, 0) and zero rotation.
        Instantiate(myPrefab, new Vector3(0, 0, 0), Quaternion.identity);
    }
}
over 4 years ago · Santiago Trujillo Report

0

Create an Action Class or an interface deriving from Monobehaviour.

public abstract class Action : Monobehaviour {
public virtual void executeAction(); 
...

And then create actual actions deriving from that abstract base:

public class DestructionAction : Action {
public override void executeAction()
{
    // the actual action code
}
... 

That way, you can create a lot of different actions. Your "Interaction Code" Script needs a Slot of type "Action" (the abstract base class).

Learn more about Overriding here: https://learn.unity.com/tutorial/overriding#5c893d46edbc2a0d28f48954

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!