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 awplays49 · Jan 31, 2015 at 07:18 PM · aienemyenemyai

Keep track of every time an int changes, including what the value is each time?

What is a good way to do this? I need to keep track of the players position every time he changes direction so my enemy ai will work.

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 Mmmpies · Feb 01, 2015 at 03:51 PM

OK your update 17 hours ago was a lot clearer. This will get a Vector3 from a list if called from the other script:

     private List<Vector3> posList = new List<Vector3>();
     private GetTheV3 myGetTheV3;
     public GameObject ScriptHolder;

     void Start()
     {
         posList.Add (new Vector3(1f, 1f, 1f));
         posList.Add (new Vector3(2f, 1f, 2f));
         posList.Add (new Vector3(3f, 1f, 3f));
         posList.Add (new Vector3(4f, 1f, 4f));
         posList.Add (new Vector3(5f, 1f, 5f));

             myGetTheV3 = ScriptHolder.GetComponent<GetTheV3>();
     }
 
     public Vector3 GetV3(int myInt)
     {
         Vector3 myV3= (Vector3)posList[myInt];
         return myV3;
     }

     public void SetV3()
     {
         float myX = transform.position.x;
         float myY = transform.position.y;
         float myZ = transform.position.z;
         posList.Add(new Vector3(myX,myY,myZ));
     myGetTheV3.AddToInt();
     }

If you call that script array1 as your update said then in the other script.

 using UnityEngine;
 using System.Collections;
 
 public class GetTheV3 : MonoBehaviour {
 
     private array1 myArray1;
     public GameObject ScriptHolder;
     private int PubInt = 5;
 
     void Start()
     {
         myArray1 = ScriptHolder.GetComponent<array1>();
     }
 
     void Update()
     {
         if(Input.GetKeyDown( KeyCode.Space))
             GetMyV3();
     }
 
     void GetMyV3()
     {
         Vector3 gotV3 = myArray1.GetV3(Random.Range(0,PubInt));
         Debug.Log(gotV3);
     }
 
     public void AddToInt()
     {
         PubInt++;
     }
 }

That's just example code the SetV3 in the first script can be called at any point from another script to record the current position, that's a guess at what you likely want and in my test would just record the same position as I put both scripts on an empty GameObject.

It just sets a random range but if you call the SetV3 that updates the int in the second script. Like I said just an example.

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 PhoenixBlackReal · Jan 31, 2015 at 09:15 PM

Here is a quick example, I'm sure you can work out from here:

 using UnityEngine;
 using System.Collections;
 
 public class followvalue : MonoBehaviour {
 
     Vector3 previous_value;
     Vector3 current_value;
     
     void Start (){
         previous_value = this.gameObject.transform.position;;
         current_value = this.gameObject.transform.position;;
     }
     
     void Update () {
         previous_value = current_value;
         current_value = this.gameObject.transform.position;
          if(previous_value != current_value){
             Debug.Log("gameobject changed position");
          }
     }
 }

Note, position is a Vector3, not int.

Comment
Add comment · Show 6 · 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 awplays49 · Jan 31, 2015 at 09:22 PM 0
Share

I need a method that saves every single change of position, so im using an array :) however i need some help. how do i use a variable to fill in as the index of an index of another script?

 first script
 
 public ArrayList mylist;
 
 void Start () {
 mylist.Add (5);
 mylist [0] = transform.position;
 }
 
 second script
 
 private ArrayList mylist2;
 private int myint = 1;
 
 void Update () {
 mylist2 = GetComponent <firstscript> ().mylist;
 transform.position = mylist2 [myint];
 }
 
 
avatar image awplays49 · Jan 31, 2015 at 09:23 PM 0
Share

thats what i tried, but it says cannot convert type object to vector3

avatar image awplays49 · Jan 31, 2015 at 09:40 PM 0
Share

@InvincibleCat do you know how to access a certain index number from another script?

avatar image Alex_May · Jan 31, 2015 at 09:43 PM 0
Share

In the Start() of your second script:

 FirstScript firstScript;
 void Start()
 {
 GameObject firstObject = GameObject.Find("name of object containing first script");
 firstScript = firstObject.GetComponent<FirstScript>();
 }

then in your update you should be able to get to the list by calling firstScript.mylist. You could also store a reference to firstScript.mylist in the Start() function (i.e. mylist2 = firstScript.mylist; in Start()).

avatar image awplays49 · Jan 31, 2015 at 09:44 PM 0
Share

can it also access the index and change it?

Show more comments

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Enemy Rigidbody Not Responding to Gravity 1 Answer

Problem with the movement of AI 1 Answer

Why do the AI get caught on trees? 0 Answers

Enemy is not chasing player. it is escaping. 1 Answer

Simple AI Error 8025 Parrsing error. 2 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