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 Zega · Dec 04, 2010 at 04:31 AM · objectdestroymissile

Destroy() not working

One of the games I'm working on to get a feel for Unity is a Missile Command game. One where the player would be able to click on the screen to get the point where the missiles would fly to and then explode. The problem I'm having at the moment is that my missiles aren't exploding when they reach the point. The missiles constantly move/translate towards the point even after reaching it. My scene is set up so that I have a collider volume catching the points for the missile destinations. A ray would shoot out of the camera, hit the collider, then a missile would move towards that point the ray hit on the collider.

In my C# code below, which is placed on the missiles, I have it set up so that if the missile is fired from any of the 3 missile launching buildings it would take the spawn point and destination point and compare the two. This is supposed to determine which "if" check to use to see if the missile has reached the point or not. If the missile isn't at the point, the "Alive()" method is executed but if the missile is at the point or exceeded the position of the destination then the "Dead()" method is executed. This is what's supposed to happen but isn't for some reason. One final thing, due to me setting up my scene a little wrong, the "z-axis" is acting as the "x-axis" in the code below. Any help is appreciated.

using UnityEngine; using System.Collections; using System;

public class PlayerMissile : MonoBehaviour {

#region Fields public float speed; private Transform MissileTransform; private Vector3 MissilePosition; private Vector3 Destination; private Vector3 Spawn; #endregion

void Start() { MissileTransform = transform; MissilePosition = transform.position; Destination = Camera.main.GetComponent<Controls>().missileDeathLoc; Spawn = Camera.main.GetComponent<Controls>().missileSpawn; }

//Update is called once per frame void Update() { if (Spawn.z > Destination.z) { if (MissilePosition.z > Destination.z && MissilePosition.y < Destination.y) { Alive(); } if (MissilePosition.z <= Destination.z && MissilePosition.y >= Destination.y) { Dead(); } } if (Spawn.z < Destination.z) { if (MissilePosition.z < Destination.z && MissilePosition.y < Destination.y) { Alive(); } if (MissilePosition.z >= Destination.z && MissilePosition.y >= Destination.y) { Dead(); } } }

void Alive() { //looks at the destination and moves towards it MissileTransform.LookAt(Destination); MissileTransform.Translate(Vector3.forward (speed Time.deltaTime)); }

void Dead() { Debug.Log("Death triggered"); //deletes the missile if at the destination and subtracts the number of missiles onscreen Camera.main.GetComponent<Controls>().missileCount--; Destroy(gameObject); }

}

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 Justin Warner · Dec 05, 2010 at 03:00 AM 0
Share

Does Death triggered get printed?

0 Replies

· Add your reply
  • Sort: 

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

No one has followed this question yet.

Related Questions

C#: Changing current position of an object in y. 1 Answer

how to raycast instantiated game characters 1 Answer

Collision with a coin 0 Answers

How to cleanly delete Object with attached Bounding Box Rig (Script)? 0 Answers

Why are Objects not getting destroyed? 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