• 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 AlphaWolf464 · Apr 13, 2019 at 04:02 PM · rigidbodytriggerboxcollider

Trigger not triggering

I have a trigger item, the istrigger being on it's box collider, also has arigidbody, and the player, who has a capsule collider, and a rigidbody. alt text

alt text

My script that handles the trigger: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityStandardAssets.Characters.FirstPerson;

public class Player : MonoBehaviour { List WildCreatures; List StoredCreatures; List OtherTrainerCreatures; GameObject[] CreaturesInInv; int nextserialnumber; bool inbattle; GameObject SpawnTile; GameObject Player1; GameObject Creature; GameObject Player1Camera; GameObject CreatureCamera; CharacterController Player1Input; CharacterController CreatureInput; // Start is called before the first frame update void Start() { nextserialnumber = 0; inbattle = false; WildCreatures = new List(); StoredCreatures = new List(); OtherTrainerCreatures = new List(); CreaturesInInv = new GameObject[4]; Vector3 spawnPos = transform.position + transform.forward * 2; GameObject Teddy = Instantiate(GameObject.FindGameObjectWithTag("Teddy"), spawnPos, transform.rotation); CreaturesInInv[0] = Teddy; Teddy.active = false; Player1Camera = gameObject.transform.GetChild(0).gameObject; Player1Input = gameObject.GetComponent(); ; }

 // Update is called once per frame
 void Update()
 {

 }

 public static GameObject CreateCreature()
 {
     int Creaturenumber = (int)Random.value;
     if (Creaturenumber == 0)
     {
         GameObject[] PossibleCreatures = GameObject.FindGameObjectsWithTag("Teddy");
         for (int i = 0; i < PossibleCreatures.Length; i++)
         {
             if (PossibleCreatures[i].transform.position.y < 0)
             {
                 return PossibleCreatures[i];
             }
         }
     }
     return GameObject.FindGameObjectWithTag("Teddy");
 }

 public void OnTriggerEnter(Collider other)
 {
     Debug.Log(inbattle);
     if (inbattle == false)
     {
         Vector3 placetospawn = transform.position + transform.forward * 10;
         placetospawn.y = (float)0.3;
         GameObject newcreature = Instantiate(CreateCreature(), placetospawn, Quaternion.Euler(0, transform.rotation.y * 100 + 180, 0));
         WildCreatures.Add(newcreature);
         WildBattle(gameObject, newcreature);
         other.gameObject.GetComponent<SpawnBlock>().Move();
     }
 }

 public void WildBattle(GameObject Player, GameObject WildCreature)
 {
     inbattle = true;
     Player1 = gameObject;
     Creature = CreaturesInInv[0];
     Creature.active = true;
     Creature.transform.position = transform.position + transform.forward * 4;
     Creature.transform.position = new Vector3(Creature.transform.position.x, (float)0.3, Creature.transform.position.z);
     CreatureCamera = Creature.transform.GetChild(0).gameObject;
     CreatureInput = Creature.GetComponent<CharacterController>();
     CreatureCamera.active = true;
     CreatureInput.enabled = true;
     Player1Camera.active = false;
     Player1Input.enabled = false;
 }

}

boxinunity.png (265.0 kB)
playerinunity.png (261.0 kB)
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by AlphaWolf464 · Apr 13, 2019 at 07:37 PM

Okay, i fixed it. My trigger was too short, and my script wasn't on the gameobject.

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 hameed-ullah-jan · Apr 13, 2019 at 06:13 PM

If this script is attached to the player, the IsTrigger bool of the player's collider must be true (checked) for OnTrigger functions to work.

Comment
Add comment · Show 1 · 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 AlphaWolf464 · Apr 13, 2019 at 07:32 PM 0
Share

Tried that, didn't work, assu$$anonymous$$g u mean the one im thinking of. Also, I thought only one had to be a trigger

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

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

Related Questions

How to check if a BoxCollider is hit by a trigger? 1 Answer

Problem with MeshColliders and Rigidbodies 1 Answer

OnTriggerEnter Inconsistant 0 Answers

Trigger Rigidbody with CharacterController 0 Answers

Moving Trigger/Platform and Moving Player calls OnTriggerEnter every frame 0 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