• 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 Daigo_The_Fast · Sep 16, 2011 at 11:48 PM · textureuvtile

Call a component with different parameters?

Hey, this is my first time using unity and I'm very happy with the power it has.

I'm just not very good in JavaScript nor on C# nor on Boo, but I do program in C++ and Ruby. I just have a question about at least one of those languages...

How do you call components or scripts in Js, C# or Boo? In C++ or C, you can call a function or a script like "MyFunction(parameter1, parameter2, parameter 3);" I have already seen this page: http://unity3d.com/support/documentation/ScriptReference/GameObject.GetComponent.html but I can't manage to understand how to tell the script what parameters to change.

I'm making a 2d platformer game in Unity and it's like 3d world constrained to 2d movement and pure 2d player (textured plane) to simulate sprite.

And I want to make the sprite to change if I press the left/right arrow or press A key to jump or D to do a dash. I have this script: http://www.unifycommunity.com/wiki/index.php?title=Animating_Tiled_texture

And I want to call it changing uvAnimationTileX, uvAnimationTileY and framesPerSecond, also changing "_MainTex" to something else:

renderer.material.SetTextureOffset ("_MainTex", offset); renderer.material.SetTextureScale ("_MainTex", size);

Is this possible?

Comment
Add comment · Show 1
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 Waz · Sep 17, 2011 at 12:11 AM 0
Share

This is two questions (how to call component functions, how to animate texture tiling). Could you split the second question off please?

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Waz · Sep 17, 2011 at 12:14 AM

It is just like C++. Get a reference to the target object and call a function or set a property on it:

 target.DoStuff(1,2,3);
 target.myProp = 123;

To get the reference (the target variable above), use GetComponent as you have noted:

 target = targetGameObject.GetComponent.<TheTargetScript>();

For best performance, keep the reference rather than finding it again every frame.

To get the GameObject containing the component, you can, for example, use GameObject.Find.

Alternatively, you can set the references from the Inspector:

 var target : TheTargetScript; // drag target to this in inspector
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 Daigo_The_Fast · Sep 19, 2011 at 04:31 PM

Thank you! But there weren't two questions... I was just asking for the component call... I already knew how to animate by tiling. :S

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Assigning UV Map to model at runtime 0 Answers

change uv of a plane so it takes a portion of texture 1 Answer

Using Rpg maker XP Tiles (2D Tile System) 2 Answers

How to texture walls in procedurally generated mesh? 1 Answer

Texture tiling based on Object size/scale 4 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