• 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 dot · Oct 05, 2010 at 11:10 PM · rubikscube

is not a part of transform/not set to an instance of an objet error

There's this bit of code I can't help myself with

script name: easearoundease.js :

var sliceCubes:Transform[];

var centralCube:Transform; var axisOfARotation = Vector3.forward; var rotationAmount = 90; var howLongRotation= 1.0;

function Update () { if(Input.GetMouseButtonDown(0)){ for(var cube : Transform in sliceCubes) cube.GetComponent(rotatearoundease).RotateObject(centralCube.position, axisOfARotation, rotationAmount, howLongRotation); } if(Input.GetMouseButtonDown(1)){} //~ for(var cube : Transform in sliceCubes) cube.RotateObject(centralCube.position, -axisOfARotation, rotationAmount, howLongRotation); }

function RotateObject(point : Vector3, axis : Vector3, rotateAmount : float, rotateTime : float) { var step : float = 0.0; //non-smoothed var rate : float = 1.0/rotateTime; //amount to increase non-smooth step by var smoothStep : float = 0.0; //smooth step this time var lastStep : float = 0.0; //smooth step last time while(step < 1.0) { // until we're done step += Time.deltaTime rate; //increase the step smoothStep = Mathf.SmoothStep(0.0, 1.0, step); //get the smooth step transform.RotateAround(point, axis, rotateAmount (smoothStep - lastStep)); lastStep = smoothStep; //store the smooth step yield; } //finish any left-over if(step > 1.0) transform.RotateAround(point, axis, rotateAmount * (1.0 - lastStep)); }

It's basically a code for Rubik's Cube attempt. for the project related to this thread: http://answers.unity3d.com/questions/22375/rubiks-cube-problem

but as you may see there's always a problem with 13th line.

if(Input.GetMouseButtonDown(0)){
    for(var cube : Transform in sliceCubes) cube.GetComponent(rotatearoundease).RotateObject(centralCube.position, axisOfARotation, rotationAmount, howLongRotation);
}

I tried putting

if(Input.GetMouseButtonDown(0)){
    for(var cube : Transform in sliceCubes) cube.GetComponent(rotatearoundease).RotateObject(GetComponent(rotatearoundease).centralCube.position, GetComponent(rotatearoundease).axisOfARotation, GetComponent(rotatearoundease).rotationAmount, GetComponent(rotatearoundease).howLongRotation);
}

thinking that "cube" might not know what's in THIS script, but no. doesn't help.

Does anyone see an error here? Thank you for help.

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 Mike 3 · Oct 05, 2010 at 11:52 PM

The code looks a bit too complicated as you have it - declare the array as:

var sliceCubes : rotatearoundease[];

and things become much easier - no more GetComponent necessary, so no chance of screwing up there, and you still just drag the object on the same way as before (you don't need to drag via the component itself, for example)

On top of that, it stops you dragging on transforms which don't have your script, which is a very good thing

Note: It's best to remove all entries from the array and re-add them fresh, otherwise things get a bit iffy

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How to have objects with multiple parents capable of seperate rotation 3 Answers

Get the rotation vector from 2 vectors 1 Answer

trying to make the inside of a rubik's cube 2 Answers

Get the rotation matrix if you have the start and end position 1 Answer

change variables in another object's script's instance 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