Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by m4s4m0r1 · Mar 27, 2013 at 03:35 PM · target

How to Set "Target" from two or more different script?

Hi, i just have a problem with my script,, I have a problem when i Set The "Target" from another script. Maybe something like this:

from script A -Give a Target> Script B -> Instantiate

from script C -Give a Target> Script B -> Instantiate

Its work when the Script A just Instantiate the Script B,, Then When Script C give an order to Script B, The Target from Script A is Changed to Target from Script C ,

How can i get the "Fix" target for my Script when i Instantiate the Script?

Sorry for my English ,, :)

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Mar 27, 2013 at 04:42 PM

I'm assuming that ScriptA and ScriptC are on other game objects, so to start, you need to get access. Here is a link:

Accessing Other Game Objects

After than it is easy. If 'Target' is a global variable of ScriptB, then with a reference to ScriptB, you set it directly. Or you could add a method to ScriptB that takes 'Target' as a parameter. If you post some of your code, we could give more precise advice.

Comment
Add comment · Show 5 · 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 m4s4m0r1 · Mar 27, 2013 at 10:57 PM 0
Share

I use GetComponent for scipt B, but still same, i use this script for Script A and C. But With The Different Target and Variable

 var Target : Transform;
 var Bullet : GameObject;
 var shoot : boolean = false;
 private var myGO : GameObject;
 function Update()
 {
 if(shoot)
 {
  ShootTheBullet();
 }
 }
 function ShootTheBullet()
 {
    myGO = Instantiate(Bullet,transform.position,transform.rotation);
    var theScript = myGO.GetComponent(ScriptB);
    theScript.Target = Target;
    Shoot = false;
 }
avatar image robertbu · Mar 27, 2013 at 11:22 PM 0
Share

So this script looks fine. Is there still a problem, or is this the solution?

avatar image m4s4m0r1 · Mar 28, 2013 at 03:51 AM 0
Share

the problem is when i Instantiate the Bullet,,, when i "Shoot", The Bullet is go to the my target, but when my bullet still go to my target, then the AI "shoot" the bullet with the target is me,my Bullet Turn Around and Attack $$anonymous$$e,, :)

I Think how can i give the Fixed Target to $$anonymous$$y Bullet?

avatar image robertbu · Mar 28, 2013 at 02:19 PM 0
Share

Can you post the script for the bullet (ScriptB). Did you make the Target you set for the bullet static?

avatar image m4s4m0r1 · Mar 31, 2013 at 12:42 PM 0
Share

yeah,,,Problem Solved

I Set a Variable in scriptB as a Static var,, when i Change it to Public,, Its Work

Thanks Very $$anonymous$$uch

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

Assigning the script over the target (from surviving island) 2 Answers

Replace "Transform" by my Mouse Target 1 Answer

Targeting problem 1 Answer

How can I get this script to work? 1 Answer

Assign a 'Transform' target to prefab by finding a 'GameObject' 1 Answer


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