Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Sep 12, 2015 at 11:29 PM by Darth_Cheree for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Darth_Cheree · Sep 12, 2015 at 04:24 PM · mathf.clamp

Error CS1031

I know there are a lot of these posts out there, but they all seem to be specific to certain instances, not anywhere looking like mine.

The errors specific; Assets/Script/BoundarySetting.cs(11,26): error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer Assets/Script/BoundarySetting.cs(12,34): error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer Assets/Script/BoundarySetting.cs(13,34): error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer Assets/Script/BoundarySetting.cs(14,34): error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer

The code I wrote;

 using UnityEngine;
 using System.Collections;
 
 public class BoundarySetting : MonoBehaviour {
 
     public float edgexMin, edgexMax;
     public float edgeyMin, edgeyMax;
     
     // Update is called once per frame
     void Update () {
     edgexMin = Mathf.Clamp = new Vector3 (-9.4f, 0.0f, 0.0f);
         edgexMax = Mathf.Clamp = new Vector3 (9.7f, 3.8f, 0.0f);
         edgeyMin = Mathf.Clamp = new Vector3 (9.5f, -3.8f, 0.0f);
         edgeyMax = Mathf.Clamp = new Vector3 (9.79f, -0.55f, 0.0f);
     
     }
 }

I am trying to make it so my dart sprite does not leave the canvas.

I know I've said this before but ANY help would be appreciated. I tried and tried using the wonderful new space shooter tutorial, he did a nice C# snippet about Mathf.Clamp but it doesn't seem to work in Unity2D. Thanks in advance folks.

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 Owen-Reynolds · Sep 12, 2015 at 04:27 PM 1
Share

Look up any example of $$anonymous$$ath.Clamp and compare to what you wrote.

Clamp is a function, which is a common program$$anonymous$$g thing. Lap, $$anonymous$$oveTowards ... are also functions. Read about how function calls and parameters work (just any book about program$$anonymous$$g. Non-Unity C# books and web pages have the best explanations.)

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by MartinLyne · Sep 12, 2015 at 04:52 PM

Maybe you want something like this? (I don't know how you are getting the canvas coords right now)

 GameObject sprite = Find("Dart");
 void Update () {
     Vector2 currentPosition = sprite.transform.position;
     // Reset location if over bounds
     currentPosition.x = Mathf.Clamp(currentPosition.x, lowerLimitX, upperLimitX);
     currentPosition.y = Mathf.Clamp(currentPosition.y, lowerLimitY, upperLimitY);
     sprite.transform.position = currentPosition;
 }

You could also look at the Unity class Bounds which might be helpful (use direct or extend it)

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 Darth_Cheree · Sep 12, 2015 at 09:58 PM

Thanks Owen, am looking now.

I can't reply to your comment Martin, so I will comment here.

I got the coordinates I wanted by positioning the sprite I don't want to leave the canvas as far to the top, bottom and sides as I want it to go (got that idea from the space shooter tutorial) and entering those coordinates in the xMin, xMax, yMin and yMax.

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

Follow this Question

Answers Answers and Comments

29 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

Related Questions

2D Camera shakes when player move fast 0 Answers

So I'm trying to rotate an object from -35 degrees to 35 degrees, or rather 325 degrees to 35 degrees 1 Answer

Vector3 does not contain a constructor that takes 4 arguments 0 Answers

Why does the gameobject "bounce back", and start rotating the opposite direction once it has reached its mathf.clamp rotation limit? 0 Answers

I have a problem with mathf.clamp…how to use it to move left and right?? 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