Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by andrewthorpe · Oct 17, 2012 at 08:38 PM · triggercollisions

Need help with a trigger problem?

I need help with the following code it will not allow me to run it i am trying to make it so that when the game object collides with the trigger it will push the game object ahead a certain amount of meters.

using UnityEngine; using System.Collections;

 public class pushcharacter : MonoBehaviour {
     private Vector3 speed = new Vector3(3, 0, 0);
     void FixedUpdate() {
         rigidbody.MovePosition(rigidbody.position + speed * Time.deltaTime);
     }
 }
 public class Transform explosion;
 public class Transform trnsfrm;
     
     void OnTriggerEnter (Collider obj)
     {
         Instantiate (explosion, trnsfrm.position, Quaternion.identity);
     }
 
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 Michael Covert · Oct 17, 2012 at 09:05 PM

When you say it won't let you run it, you mean it won't compile? Normally, telling us the errors you're seeing more specifically can help pinpoint the problem.

In this case, I think your problem is the declaration of your public variables explosion and trnsfrm, they shouldn't have class before them - i.e,

 public Transform explosion;
 public Transform trnsfrm;

Does that solve the problem for you?

Comment
Add comment · Show 3 · 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 andrewthorpe · Oct 18, 2012 at 09:00 PM 0
Share

Still the problem heres the code:

public class pushcharacter : $$anonymous$$onoBehaviour public class Transform explosion; public class Transform trnsfrm; { private Vector3 speed = new Vector3(3, 0, 0); void FixedUpdate() { rigidbody.$$anonymous$$ovePosition(rigidbody.position + speed * Time.deltaTime); } void OnTriggerEnter (Collider obj) { Instantiate (explosion, trnsfrm.position, Quaternion.identity); } }

---------The error it says is under the public part of public class Transform, it says "type expected".

Thanks so far though!

avatar image Michael Covert · Oct 18, 2012 at 09:28 PM 0
Share

You should only use the class keyword when declaring a class. It looks like you're trying to declare instances of a class, in which case you shouldn't use the class keyword. It's expecting you to provide a type ins$$anonymous$$d - which you do, but after the erroneous class keyword, so they compiler's already "thrown-up" so to speak. Removing the class keyword from your two Transform variable declarations should solve the problem.

avatar image Seth-Bergman · Oct 18, 2012 at 10:02 PM 0
Share

Correct, this will solve the compiler error, but you've still got some work to get the desired behavior... The only thing that is initiated by your trigger is to instantiate your explosion.. But your movement code is in FixedUpdate, which is not going to wait for the trigger, it will be moving the whole time..

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

11 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

Related Questions

Gameobject not registering collisions 1 Answer

Can't click gameobject when over another trigger? 1 Answer

How to use multiple Colliders for an enemy to detect multiple collisions in different areas to determine the damage to the enemy? I.E. Headshot etc. 1 Answer

Very strange trigger behavior in Unity2D (4.5) 0 Answers

Find all objects currently colliding with trigger 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