Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
This question was closed Feb 16, 2017 at 04:55 PM by GKuhns for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by GKuhns · Feb 16, 2017 at 12:10 AM · importjet

How do I call the immobilize function to kill the AI jet?

I'm looking at the AeroplaneController.cs script attached to the AI Jet from the Standard Assets Package. It has a function for "immobilizing" the plane...

How would I go about calling this function? Here is the pertinent code from AeroplaneController.cs:

   // Immobilize can be called from other objects, for example if this plane is hit by a weapon and should become uncontrollable
         public void Immobilize()
         {
             m_Immobilized = true;
         }


I have a "weapon" which is fired by left mouse click, and I want to call that Immobilize function when I shoot a jet...

Also, it occurs to me that if I'm using multiple AI jets, I might have a problem wherein I disable all of them whenever I kill one of them...

I'm very new to coding (trying to help my daughter get started with unity) so if anyone has any helpful suggestions or advice, that would be greatly appreciated.

We tried

 void Update()
     { 
         if(Input.GetMouseButtonDown(0) == true)
         {
             AeroplaneController.m_Immobilized = true;
         } 
     }

but we get the error: Unknown identifier: AeroplaneController...

Clearly we're missing something, but we've been unable to find the solution.

Thanks in advance, to anyone willing to point us in the right direction.

Cheers!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by GKuhns · Feb 16, 2017 at 04:34 AM

Thank you Igor,

I tried putting what you wrote into a script, but I get errors: "The type or namespace name 'AeroplaneController' could not be found. Are you missing 'UnityStandardAssets.Vehicles.Aeroplane' using directive?

I started watching the video, but it's difficult to jump into the middle of a tutorial series - I think I'll have to check it out from the start to understand better.

Also, I'm confused; would the "gameObject from where (I) want the code to work" be the AI Jet I'm trying to kill? It already has the AeroplaneController script attached to it... Sorry, I'm not quite understanding what I should do...

This is what I thought you meant, but it gets the aforementioned error:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class JetKill : MonoBehaviour {
     
     public AeroplaneController incarnationOfAeroController;
 
 
     void Update()
     { 
         if(Input.GetMouseButtonDown(0) == true)
         {
             incarnationOfAeroController.Immobilize();
         } 
     }
 }
 

What am I doing wrong?

Thanks again, I appreciate your willingness to help - sorry I'm still a bit confused.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image IgorAherne · Feb 16, 2017 at 09:37 AM 0
Share

Yes, this code looks fine

Also, I'm confused; would the "gameObject from where (I) want the code to work" be the AI Jet I'm trying to kill?

Could be, but it makes more sense to add it to the player or someone who tries to kill the jet. Hence, we should stick the script you've mentioned on a player, etc. We then prepare a slot, then specify which object we are trying to imobilize by dragging it into the slot (from the Hierarchy panel)

Also, check this link to resolve the error; $$anonymous$$ost of the errors can be copy-pasted into google, but sometimes require simplification. For example, in future the errors might be similiar to the errors of other users, but might have different file names. Hence, simplify the google query to amend these.

avatar image GKuhns · Feb 16, 2017 at 04:53 PM 1
Share

Yes! Thank you so much - this has been driving me nuts, and I am thrilled to finally have the right answer.

This info will undoubtedly help me in numerous instances in the future, so, many more thanks in advance!

:)

avatar image
1

Answer by IgorAherne · Feb 16, 2017 at 01:59 AM

There are concept of Classes and Objects

Objects are physical instances of classes. The latter you can think of as some sort of "blueprints", a non-existing set of instructions.

with AeroplaneController.m_Immobilized = true; you just ordered a "blueprint" to execute something. But it can't - it's not physically present anywhere, it's just a blueprint.

You instead need to find objects in the scene which are the incarnations of such a class. These objects are monobehaviors, which are attached to gameObjects, similar to any other component.

You can do it with GameObject.Find() which a fairly expensive function to call, don't do it every Update.


Alternativelly, you can create a slot, into which you can drag-drop the object. You should declare the slot from inside of your script. In the script where you want to have access via the slot, write:

public YourBluePrintName yourVariableName;

for example AeroplaneController incarnationOfAeroController;

You can then drag-and-drop this monobehavior "blueprint" onto the gameObject from where you want the code to work. Now, drag-and drop the gameObject which has AeroplaneController script attached to it, into the slot.

Don't forget to do something with this slot, so it's not invain. You should do it from inside the script, for example

 void Update()
      { 
          if(Input.GetMouseButtonDown(0) == true)
          {
             incarnationOfAeroController.Immobilize();
          } 
      }


At the current stage, this video is pretty much the best you can find (I've scrubbed to the needed time, you will enjoy this lesson like many others)

https://youtu.be/auXSM1CvRVc?t=1h48m17s

:)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

100 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to import a rigged model (skeleton), so the MeshRenderers are not modified during the Unity import? 1 Answer

Texture Becomes Blotchy in Unity 0 Answers

Imported Assets Can't Be Used 0 Answers

wierd black spots/shadows on mesh from blender to unity 0 Answers

Mesh and material missing after .fbx Import as AssetBundle 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges