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 TheRichardGamer · Nov 15, 2013 at 07:14 AM · gameobjecttransformvector3

Cannot conver UnityEngine.Transform to UnityEngine.GameObject

I have this annoying error with my script, how do I fix it? My script: var TactScript : ThrowTact;

 public var Health : float = 100.0f;
 
 var Player : GameObject;
 
 var DefSpawn : Vector3;
 
 var Tact : GameObject;
 
 
    
 function Update () {
 
      
          Tact = GameObject.FindGameObjectWithTag("Tact").transform;
 
   if(Health == 0 && TactScript.HasTact == true){
   Player.transform.position = Tact.transform.position.up * 3;
   Health = 100;
   }
 
   else
   
   if(Health == 0 && TactScript.HasTact == false){
   Player.transform.position = DefSpawn.transform.position;
   Health = 100;
   }
 
 }
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

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by brain56 · Nov 15, 2013 at 07:20 AM

The problem is this line:

 Tact = GameObject.FindGameObjectWithTag("Tact").transform;

Tact is a GameObject, and you're assigning the Transform of the GameObject tagged "Tact". A `Transform` cannot be converted into a `GameObject`, even if typecasted.

What you should do is delete the .transform at the end of that line. That should fix the error.

Comment
Add comment · Show 1 · 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 TheRichardGamer · Nov 15, 2013 at 10:09 AM 0
Share

Ok, but if I want to go up in Y by 3 if it's a transform, how do I do that?

avatar image
1

Answer by zanearn · Nov 15, 2013 at 07:18 AM

Change this line:

 Tact = GameObject.FindGameObjectWithTag("Tact").transform;

To:

 Tact = GameObject.FindGameObjectWithTag("Tact");
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
avatar image
1

Answer by Mefistofel · Nov 15, 2013 at 07:21 AM

Transform - is the component of Game object(it added by default). Your error - DefSpawn is Vector3, it does not contain transform, this is simple 3d vector. Player.transform.position = DefSpawn;

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

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

20 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

Related Questions

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

Mouse-following script freezes Unity. 1 Answer

Reverse Look up ( have transform want the gameObject of that transform) 2 Answers

unknown axis of rotation 1 Answer

how do i fix my script in the content below? 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