Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Why aren't the values being transfered to the other script?

Discussion in 'Scripting' started by circleline, Mar 21, 2015.

  1. circleline

    circleline

    Joined:
    Nov 29, 2014
    Posts:
    42
    Hey Guys! I have a problem. Here's my script
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class TapControl_L : MonoBehaviour {
    5.  
    6.     public float addValue = 0;
    7.  
    8.     void Start(){
    9.    
    10.  
    11.        
    12.     }
    13.        
    14.     void Update ()
    15.     {
    16.  
    17.         //touch code
    18.         Touch myTouch = Input.GetTouch(0);
    19.        
    20.         Touch[] myTouches = Input.touches;
    21.         for(int i = 0; i < Input.touchCount; i++)
    22.         {
    23.             if(Input.touchCount > i){
    24.                
    25.                
    26.                 //if touch has began/moved/stationary then
    27.                 if (Input.GetTouch(i).phase == TouchPhase.Began || Input.GetTouch(i).phase == TouchPhase.Stationary || Input.GetTouch(i).phase == TouchPhase.Moved) {
    28.                    
    29.                     //creating a raycast
    30.                     Vector2 ray = Camera.main.ScreenToWorldPoint(Input.GetTouch(i).position);
    31.  
    32.                     RaycastHit2D hit = Physics2D.Raycast(ray, (Input.GetTouch(i).position));
    33.                     //if raycast hits the left tap ctrl
    34.                     if (hit.collider && hit.collider.tag == "Tap_L"){
    35.  
    36.                         addValue = 1;
    37.                         //to test if working
    38.                         print (addValue);
    39.  
    40.                
    41.                     }
    42.                 }
    43.             }
    44.         }
    45.     }
    46.    
    47. }
    Everything works as planned in this code, but the problem comes here.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class playerControl_B : MonoBehaviour {
    5.  
    6.  
    7.  
    8.  
    9.     public float value = 180;
    10.  
    11.  
    12.  
    13.  
    14.  
    15.  
    16.     // Use this for initialization
    17.    
    18.     void Start () {
    19.  
    20.  
    21.  
    22.        
    23.     }
    24.    
    25.     // Update is called once per frame
    26.  
    27.  
    28.         // Update is called once per frame
    29.         void Update () {
    30.            
    31.             GameObject death = GameObject.Find("Portal");
    32.             IfCollideDelete balldeath = death.GetComponent<IfCollideDelete>();
    33.  
    34.            
    35.  
    36.            
    37.             if (balldeath.death == false) {
    38.                
    39.            
    40.                    
    41.  
    42.                    
    43.                         GameObject addValue = GameObject.Find ("PlayerControl");
    44.                         TapControl_L up = addValue.GetComponent<TapControl_L> ();
    45.  
    46.                         value += up.addValue;
    47.            
    48.                         Vector3 temp = transform.eulerAngles;
    49.                         temp.z = value;
    50.                         transform.eulerAngles = temp;
    51.  
    52.                 }
    53.            
    54.         }
    55.  
    56.        
    57.  
    58. }
    The thing is that up.addValue is not being added to value at all, why is that?
     
  2. circleline

    circleline

    Joined:
    Nov 29, 2014
    Posts:
    42
    Bump! really need this