Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Mxkee · Sep 01, 2018 at 04:13 AM · scalex-axisnegativex

How can I make my character be larger through a script even when he turns to his -x value?

I can make my character bigger but i have ran into a problem. When he turns left it changes his x value to -x which causes the addition to go the opposite way.

heres the code, i have a few other things going on but d_NewPosition is the scale of the character and the last if and else statement is what i tried. Im new to c# so I need alot of help with this

 using System.Collections; 
 using System.Collections.Generic; 
 using UnityEngine; 
 using UnityEngine.UI;
 
 public class cat : MonoBehaviour 
 {
     public AudioSource someSound; public GameObject Player; Vector3 d_NewPosition;
 
     Rigidbody2D rb;
     float dirX, moveSpeed = 5f;
     [SerializeField]
     Text coinCounter;
     [SerializeField]
     GameObject coinMagnet;
     int coinsNumber;
 
     // Use this for initialization
     void Start()
     {
         rb = GetComponent<Rigidbody2D>();
         d_NewPosition = Player.transform.localScale;
     }
 
     // Update is called once per frame
     void Update()
     {
         dirX = Input.GetAxisRaw("Horizontal") * moveSpeed;
         coinCounter.text = coinsNumber.ToString();
         coinMagnet.transform.position = new Vector2(transform.position.x, transform.position.y);
        
         if (Input.GetButtonDown("Jump") && rb.velocity.y == 0)
         {
             rb.AddForce(Vector2.up * 700f);
         }
     }
 
     void FixedUpdate()
     {
         rb.velocity = new Vector2(dirX, rb.velocity.y);
     }
 
     void OnTriggerEnter2D(Collider2D col)
     {
         if (col.gameObject.tag.Equals("Coin"))
         {
             Destroy(col.gameObject);
             coinsNumber += 1;
             someSound.Play();
 
             if (d_NewPosition.x >= 0)
             {
                 d_NewPosition += new Vector3(.1f, .1f, 0);
             }
             else 
             {
                 d_NewPosition -= new Vector3(.1f, 0, 0);
             }
         }
     }
 }

Comment
Add comment · Show 2
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 eses · Sep 01, 2018 at 07:41 AM 0
Share

Hi @$$anonymous$$xkee

Your question makes very little sense without seeing an image / sketch of what you are trying to do.

You have field, that you call "d_NewPosition", but you actually store to it your Player's scale - Not position?

Then you do:

  if (d_NewPosition.x >= 0)
 {
      d_NewPosition += new Vector3(.1f, .1f, 0);
 }



What do expect to happen?

You are modifying x and y of your Vector3 value?

But you don't seem to even apply this value back to your scale, or position.

And you only get your d_NewPosition in start, not later.

Please rephrase this question if possible, it is hard to understand.

avatar image Mxkee eses · Sep 01, 2018 at 03:18 PM 0
Share

@eses

im so sorry, basically what im trying to do is make my character larger. so i add .1 to his x and y scale. BUT when he turns to his left his x value turns to -x which makes him look left, and my problem with that is when he is looking to his negative x, it still adds .1 which makes it go from -1 to -0.9, ultimately making him smaller in his x value. what other info do you need? i need this to work

0 Replies

· Add your reply
  • Sort: 

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

148 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Scaling material without saving scale on original material 1 Answer

How to create a simple mobile water inside a 3D container? 0 Answers

If statement not getting called after Lerping a Scale 1 Answer

LocalScale is not taking effect at runtime 1 Answer

Scale compensate supported or not supported? 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