• 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 SmityBoy · Feb 19, 2014 at 03:47 AM · vector3script errorclimb

Why is my climbing script not working?

So I am very new to unity and C# and want to make a small level for fun. I would like to be able to make it so when the player walks towards the wall the automatically climb up it (No animations yet) So I created a cube and made it a trigger and invisible. I have made a small script but cant figure out what is stopping it from working. This error message comes up (Expression denotes a type', where a variable', value' or method group' was expected)

Here is my code: using

 UnityEngine;
 using System.Collections;
 
 public class FenceClimbing : MonoBehaviour {
     void OnTriggerEnter(Collider other){
     transform.position += Vector3 (0, 1, 0);
         }
 }

Can you please tell me what is wrong and why?

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 robertbu · Feb 19, 2014 at 03:48 AM

In C#, line 6 needs to be:

 transform.position += new Vector3 (0, 1, 0);
Comment
Add comment · Show 7 · 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 SmityBoy · Feb 19, 2014 at 12:32 PM 0
Share

Thank you for the help, but my script only works once, how can I make the ontriggerenter work all the time?

avatar image SmityBoy · Feb 19, 2014 at 02:01 PM 0
Share

Thank you it all works now, but how do I make the trigger repeat? It only works once.

avatar image robertbu · Feb 19, 2014 at 03:40 PM 0
Share

OnTriggerEnter() fires each time the object enters the trigger area. If you want something to fire for each frame while an object is in the trigger area, use OnTriggerStay().

avatar image SmityBoy · Feb 19, 2014 at 09:24 PM 0
Share

I want something that fires when someone runs through an area every time. At the $$anonymous$$ute the character keeps getting hit into the air until he moves out the way off the trigger cube(He keeps going up even when not in the cube). How can I make it so he go up then as soon as he leaves the cube he stops going up. another way I tried was: using UnityEngine; using System.Collections;

public class FenceClimbing : $$anonymous$$onoBehaviour { void OnTriggerEnter(Collider other){ transform.position += new Vector3 (0, 1, 0); Debug.Log; }

 }

But this didn't work as the character only ran up the fence twice then wouldn't do it any more.

avatar image snaveproductions · Feb 20, 2014 at 02:32 AM 0
Share

like was previously mentioned. try using the OnTriggerStay function. like this.

 void OnTriggerStay(Collider other){
 
 /*you dont want just anything to set off the trigger so you specify a tag for the player*/
     
       if(other.tag == "Player"){
           transform.position += new Vector3(0,1,0);
      }
 }
Show more comments

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

19 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

Related Questions

Zero out character velocity? 1 Answer

How do I make the bullet Tracer move towards the location of where the bullet hole prefab gets instantiated? 2 Answers

How to get axially symmetric vector3? 3 Answers

Obtain angle from given rotation 1 Answer

Moving a cube on the X-axis only moves by 1 unit? 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