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 /
  • Help Room /
avatar image
0
Question by SpectrumWolf · Aug 01, 2013 at 02:01 AM · c#

How do I move an object in C#?

I am new to using Unity to script, and I just started C# (and it looks similar to C++ so far).

Anyways, I tried to use this to find the objects position and change it.

 using UnityEngine;
 using System.Collections;
 
 public class NewBehaviourScript: MonoBehaviour
 {
     
     
     void Start (){
 
         Transform.Position.X = 2;
         Debug.Log("Test");
 
     }
 }

Instead I get an error, so how do I change size, position, and such?

Thanks.

Comment
Add comment · Show 3
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 pickle chips · Aug 01, 2013 at 02:19 AM 1
Share

Considering this is the bare basics of unity scripting, I would suggest doing more research or learning a bit more before you ask a question. This could easily be found in a beginners tutorial :p

avatar image TheFish657 pickle chips · Dec 29, 2015 at 09:10 PM 2
Share

@pickle chips Considering this is a forum for questions and answers and that this person had asked a question, by logic you should answer ins$$anonymous$$d of making a comment about how he should be going elsewhere to get said answer. That is all.

avatar image Periata TheFish657 · Sep 03, 2016 at 11:24 AM 1
Share

Agreed. I'm also a beginner, but all the tutorials I can find for beginners are video-based, and I'm not good at learning stuff like this from videos -- I much prefer written information -- so questions like this are extremely useful to me.

1 Reply

· Add your reply
  • Sort: 
avatar image
5

Answer by jacobschellenberg · Aug 01, 2013 at 02:21 AM

using UnityEngine; using System.Collections;

 public class NewBehaviourScript: MonoBehaviour
 {
     public float movementSpeed = 10;
  
     void Update(){
  
        transform.Translate(Vector3.right * movementSpeed * Time.deltaTime);
  
     }
 }


transform is the current object this script is attached to. Translate calls the Translate properties. Vector3.right (might be capital Right), tells the object to move on the X axis on the positive direction. You multiply this by movementSpeed to increase the units moved, and lastly by Time.DeltaTime to ensure the object is moving at a time based speed rather then by how fast your processor can move it.'

You can also do, Vector3.up, right, left, down, forward, back. For size you would do, transform.localScale = new Vector3(10,10,10);

This is really basic, but you'll get it :)

Hope this helps :)

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 BadSeedProductions · Feb 07, 2015 at 03:05 AM 0
Share

: Operator -' cannot be applied to operands of type UnityEngine.Vector3' and `int'

How to choose where to move it to?

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

23 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

Related Questions

How to make enemy chase player. Basic AI 7 Answers

How to Make a simple GUI using unity C# and Kinect 0 Answers

How to create an if statement for each element within a list C# 2 Answers

C# Rigidbody Rotation Resets 1 Answer

Help with a simple jump script 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