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 Wes 1 · Jan 03, 2011 at 07:59 PM · inspectorvar

Cant set default var value to script?

I have a transform var on my script. And I want to drag and drop something from the hierarchy to the var slot in the inspector, but I cant. It highlights as if it will drop, but it remains to say "none" also, I was able to do it once! I dropped a none-prefab object from the hierarchy to the Inspector, and now I cant do it. I've been trying on this for days and you can understand my frustration.

also, I can drop prefabs into the var slot, but only prefabs. Here's my script if that helps.

var LookAtThis : Transform; var elaser : Transform; var damp = 2;

function Update () { if(Vector3.Distance(LookAtThis.position,transform.position) < 800){ var rotate = Quaternion.LookRotation(LookAtThis.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, rotate,damp Time.deltaTime); transform.Translate(0,0, 10 Time.deltaTime);

}

} InvokeRepeating("fireAtPlayer",1,2);

function fireAtPlayer() { if(Vector3.Distance(LookAtThis.position,transform.position) < 800){ Instantiate(elaser,transform.Find("espawnpoint").position,transform.rotation); } }

function OnCollisionEnter(hit : Collision) { if(hit.gameObject.tag == ("Player")) Debug.Log("Watch it!"); }

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
1
Best Answer

Answer by Loius · Jan 03, 2011 at 08:08 PM

You can't drag game objects to scripts' default values. If you have an actual object with this script attached, you'll be able to drag game objects to its properties, otherwise you can only use prefabs.

Comment
Add comment · Show 3 · 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 Wes 1 · Jan 03, 2011 at 09:31 PM 0
Share

Okay, I understand. I must be going about this all wrong then, the way I'm trying to do it is, create an enemy prefab that spawns and goes towards the player,which I've tried as a prefab and a simple game object, shooting at him and so on. I am using transform var to define the player as a target. Is this the correct method for enemy movement? because I have no idea how to do it otherwise,aside from using gameOnject.name which doesn't seam to work too well with transform.position. If you think it best I'll post this as a new question.

avatar image Loius · Jan 04, 2011 at 08:41 PM 0
Share

If you have a Player object and an Enemy object in your hierarchy, you can drag the Player object to the Enemy's script and it'll work. THe problem with just using prefabs is the enemy will look at the player prefab's position, which doesn't change. If you don't want to do it like that (you don't) you can tag the player object "player" and find it in the enmy by saying "playerTransform = GameObject.FindObjectWithTag("player")"

avatar image Loius · Jan 04, 2011 at 08:42 PM 0
Share

*the problem with using prefabs ins$$anonymous$$d of gameobjects as default values

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

No one has followed this question yet.

Related Questions

Why won't values show in inspector or print in console? 1 Answer

Way to update a Script's new variables in the inspector without loosing references? 1 Answer

Inspector doesn't refresh in dinamical script change 0 Answers

Is there a way to add another slot for a script in the Inspector? 1 Answer

Variables assigned in the inspector of a script don't seem to work when instantiating them via AddComponent 0 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