Variable value still zero after assigned a value

Altiano Gerung

I'm making a simple game using Unity where the player needs to pick up coins as much as possible. When the player hits the coin, the coin will disappear and the score will be incremented, for example by 1, here's my script

#pragma strict

var coinEffect : Transform;
var coinValue = 2;


function OnTriggerEnter (info : Collider) {
    if (info.tag == "Player") {
        // Debug.Log("Ball is picked up");
        var effect = Instantiate(coinEffect, transform.position, transform.rotation);

        GameMaster.currentScore += coinValue;
        Debug.Log(coinValue);

    };
}

The problem is the variable coinValue is printed 0 when I print it to the console.

Any idea Why?

UPDATE i don't know why but if i declare another varible for example number = 12 and printed it.. It's working. But maybe this is a really strange case with the variable name.. I Don't Know.. Maybe, just maybe there is a flaw in their program for this varible name

maZZZu

Because you are using unityscript (not javascipt) the variable defined out side of the functions is set within the inspector view of the unity. Changes in the code to the initial values of these variables don't affect to values that are set from the inspector.

Select the GameObject you have attached the script to and find the script in the inspector view. There you can see the variable.

enter image description here

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Why the prevoius value still exists after reinitialaize variable - PHP

분류에서Dev

Variable is assigned but its value is never used (C#)

분류에서Dev

a value of type struct cannot be assigned

분류에서Dev

default value assigned to an attribute of a function is not carrying it in php

분류에서Dev

Method to assigned value to array using loop

분류에서Dev

Displaying the assigned value in the MySQL DB in a select tag

분류에서Dev

AngularJS - select with zero(0) value

분류에서Dev

Variable losing original value after a new instance is manipulated

분류에서Dev

Variable is null after setting value on FB.api function

분류에서Dev

IntelliSense: a value of type "void" cannot be assigned to an entity of type "double"

분류에서Dev

Disable button if input value is zero only by regexp

분류에서Dev

display annotation for zero value in google charts

분류에서Dev

why std::string is zero initialized to indeterminate value

분류에서Dev

Reset the Identity column value to zero in sybase

분류에서Dev

Variable changes value unexpectedly

분류에서Dev

the value of local variable is not used

분류에서Dev

Value not storing in powershell variable

분류에서Dev

variable value based on value in different dataframe

분류에서Dev

Is checking if a variable is equal to a value and then returning that value redundant?

분류에서Dev

SHELL environment variable still points to zsh after using bash

분류에서Dev

Difference between set variable "value" and set variable value?

분류에서Dev

Change value of variable with jquery or javascript

분류에서Dev

Display exact value of a variable in R

분류에서Dev

How to format a variable in Ansible value

분류에서Dev

KineticJS Setting a Variable Value On an Event

분류에서Dev

Javascript change value of global variable

분류에서Dev

'unsigned variable: value' C++

분류에서Dev

Bash - Setting function value as a variable

분류에서Dev

Storing pointer value into separate variable

Related 관련 기사

  1. 1

    Why the prevoius value still exists after reinitialaize variable - PHP

  2. 2

    Variable is assigned but its value is never used (C#)

  3. 3

    a value of type struct cannot be assigned

  4. 4

    default value assigned to an attribute of a function is not carrying it in php

  5. 5

    Method to assigned value to array using loop

  6. 6

    Displaying the assigned value in the MySQL DB in a select tag

  7. 7

    AngularJS - select with zero(0) value

  8. 8

    Variable losing original value after a new instance is manipulated

  9. 9

    Variable is null after setting value on FB.api function

  10. 10

    IntelliSense: a value of type "void" cannot be assigned to an entity of type "double"

  11. 11

    Disable button if input value is zero only by regexp

  12. 12

    display annotation for zero value in google charts

  13. 13

    why std::string is zero initialized to indeterminate value

  14. 14

    Reset the Identity column value to zero in sybase

  15. 15

    Variable changes value unexpectedly

  16. 16

    the value of local variable is not used

  17. 17

    Value not storing in powershell variable

  18. 18

    variable value based on value in different dataframe

  19. 19

    Is checking if a variable is equal to a value and then returning that value redundant?

  20. 20

    SHELL environment variable still points to zsh after using bash

  21. 21

    Difference between set variable "value" and set variable value?

  22. 22

    Change value of variable with jquery or javascript

  23. 23

    Display exact value of a variable in R

  24. 24

    How to format a variable in Ansible value

  25. 25

    KineticJS Setting a Variable Value On an Event

  26. 26

    Javascript change value of global variable

  27. 27

    'unsigned variable: value' C++

  28. 28

    Bash - Setting function value as a variable

  29. 29

    Storing pointer value into separate variable

뜨겁다태그

보관