• 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 kingracos · Jul 30, 2014 at 06:01 PM · score

i cant figure this out i have 2 scripts and a static variable i need the variable to add 1 everytime the enemy hits me.

these are the two scripts this one is the one the enemy that comes in contact with you has

 var target : Transform;
 var moveSpeed = 3; 
 var rotationSpeed = 3; 
 var range : float=10f;
 var range2 : float=10f;
 var stop : float=0;
 var myTransform : Transform; 
 function Awake()
 {
     myTransform = transform; 
 }
  
 function Start()
 {
      target = GameObject.FindWithTag("Player").transform; 
  
 }
  
 function Update () {
     //rotate to look at the player
     var distance = Vector3.Distance(myTransform.position, target.position);
     if (distance<=range2 &&  distance>=range){
     myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
     Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
         }
  
  
     else if(distance<=range && distance>stop){
  
     //move towards the player
     myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
     Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
     myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
     }
     else if (distance<=stop) {
     myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
     Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
     }
  
  
 }
 
 function OnTriggerEnter (info : Collider)
 {
     if (info.tag == "Player")
     {
         dronescore.droneScore += 1;    
     }
 }

and this one is the one the empty gameobject has to hold the variables and display the score

 #pragma strict
 
 static var droneScore : int = 0;
 var test = droneScore;
 
 function Update (){
     test = droneScore;
 }
 
 function OnGUI () {
 
 }

right now I have the test variable to see if the score will go up when the two objects collide and it doesn't plz help thnx in ahead.

Comment
Add comment · Show 2
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 meat5000 ♦ · Jul 30, 2014 at 06:14 PM 0
Share

Have you tried, just

 droneScore += 1; 

  
avatar image kingracos · Aug 04, 2014 at 02:15 PM 0
Share

yes its in there because its static variable it has the script in front of it

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by sirbranedamuj · Jul 30, 2014 at 07:16 PM

 myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;

This code will not cause a collision. Your object is not moving, it is teleporting very small distances.

In order to cause a collision event (or a trigger event), your object needs to have a rigidbody and needs to be moving with velocity. For instance,

 rigidbody.velocity = Vector3.forward * moveSpeed;
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 kingracos · Jul 31, 2014 at 12:55 PM 0
Share

now my enemy just runs around doesn't chase my character

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Problem with online high score 4 Answers

Basic Game Score Question. 1 Answer

How do I display the final score? 1 Answer

How to add score/health ? 2 Answers

calculate playerprefs and display 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