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 guachitonico · May 07, 2013 at 09:24 PM · errorpositionvector3

Cannot implicitly convert type 'int' to 'UnityEngine.Vector3'

Hi,

I have recently started to use Unity, and since I'm not a C# expert, I had some problems.

I want to make a car go from behind a building to another building, and loop that so when the car reaches the building, it teleports to the original building to do the same path again and again...

The problem is that I don't know how to express 'When it reaches X position' without getting an error. The error happens at line 13. Also, I noticed I can't put Space.World in Transform.Traslate (it says * isn't a valid operator for Vector3 and Space). Why?

CODE:

 using UnityEngine;
 using System.Collections;
 
 public class FixedPath : MonoBehaviour {
 
     private Transform transform;
     
     void Start() {
 
     }
     // Update is called once per frame
     void Update () {
         if(transform.forward = -32) {
             transform.Translate(Vector3.forward * Time.deltaTime);
         }
         else {
             transform.forward = -27;
         }
             
     }
 }

I'm sorry for being a noob, i know it's boring to answer stupid questions.

Thanks!

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
1

Answer by robertbu · May 07, 2013 at 09:34 PM

transform.forward is a vector point forward in world space, so it has three numbers x,y,z. For your task, you want to check and change the position of the object. Something like:

 void Update () {
     if(transform.position.z > -27.0f) 
         transform.position.z = -32.0f;
 
     transform.Translate(Vector3.forward * Time.deltaTime);
 }

As for 'Space.World,' I would have to see the exact line of code that generated the error. You likely tried to multiple rather than put in a comma.

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
0

Answer by KMKxJOEY1 · May 07, 2013 at 09:33 PM

this:

if(transform.forward = -32)

must be

if(transform.forward == -32)

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
0

Answer by Eric5h5 · May 07, 2013 at 09:33 PM

Transform.forward is a Vector3 containing the forward vector for that transform; it can't be an int like "-32". Space.World is an enum and can't be used in math operations like that. See the code examples in the docs for Translate for the exact syntax. Also, you should not have a private variable called "transform". That already exists by default, and means "gameObject.transform".

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

15 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

Related Questions

Method Must have a Return Type (Vector3 x,y,z) 2 Answers

Instantiate object in C# 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Tansform.position assign attempt for 'Enemy(Clone)' is not valid. Input position is {NaN, NaN, NaN} 0 Answers

What is wrong with my zipline script? 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