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 Robomaster · Sep 03, 2012 at 10:22 PM · triggertile

Trigger Effect Error

Hello, i have a trigger enter script that only seems to work when i attach it to the floor tiles and the player but i want to only want it to be attached to the floor tiles becuase if its attached to both the floor tiles and the players it will create problems in the future. heres my script

 using UnityEngine;
 using System.Collections;
 public class Action : MonoBehaviour {
 
     void OnTriggerEnter(Collider other){
         Movement2 m = (Movement2)GetComponent("Movement2");
         m.AdjustCurrentAction(-1); 
     }
 
     // Use this for initialization
     void Start () {
     }
 
     // Update is called once per frame
     void Update () {
     } 
 } 

The floor tile has a box collider and a mesh renderer attached to it

the player has a mesh renderer, box collider and rigidbody added to it

please help thanks in advance

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 Robomaster · Sep 03, 2012 at 10:41 PM 0
Share

sry if that didnt make sense, okay so i have a chess like type of game and i want the player for example to move a certain number of tiles away. So i have created a script that when the player enters a tiles trigger it takes away one point from the players action points. but in order for that script to work it needs to be attached to the tile and the player. But since some tiles take away more action points than others, having the script attached to the player is a problem. So i was wondering if you could tell me what i could do to with this script so that it doesnt need to be attached to the player in order for it to work. P.S. the tile has a box collider and mesh renderer added to that and the player has a mesh renderer, box collider, and rigidbody added to it

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Anusha · Sep 04, 2012 at 08:42 AM

remove the script from player... then tag ur player as "player". now only ur tile has this script attached to it. so now when ur player moves over the tiles this will trriger

 void OnTriggerEnter(Collider other)
 {
     if(other.transform.tag == "player")
     {
         GameObject m_Player = GameObject.Find("player");//assuming ur player is named player
        Movement2 m = (Movement2)m_Player.GetComponent("Movement2");
        m.AdjustCurrentAction(-1); 
     }
 }
 }

what this is doing is...when any collider enters the tile,it checks whether its the player, if yes then it finds ur player and get the Movement2 script and calls the m.AdjustCurrentAction(-1) function.

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 Robomaster · Sep 04, 2012 at 01:16 PM 0
Share

Thanks! but when i used ur script unity said m_player doesnt exsist in the current context

avatar image Anusha · Sep 04, 2012 at 01:39 PM 0
Share

sorry typo mistake.. change the below line... its m_Player...

$$anonymous$$ovement2 m = ($$anonymous$$ovement2)m_Player.GetComponent("$$anonymous$$ovement2");

avatar image Anusha · Sep 04, 2012 at 01:47 PM 0
Share

if it worked please accept the answer

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

10 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

Related Questions

How to apply more than one trigger on a single gamebject 1 Answer

Tile-Based Movement - Collision 1 Answer

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

2D TileMap with 3D Tiles (Path of exile like). 0 Answers

Delay audio collisions 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