GetSpeed









How do I use Get Speed
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: ThirdPersonController.cs Copy
426     public float GetSpeed()
427     {
428         return moveSpeed;
429     }
File name: IdleRunJump.cs Copy
33     void Update ()
34     {
35         if( m_PhotonView.isMine == false && PhotonNetwork.connected == true )
36         {
37             return;
38         }
39
40         if (animator)
41         {
42             AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);
43
44             if (stateInfo.IsName("Base Layer.Run"))
45             {
46                 if (Input.GetButton("Fire1")) animator.SetBool("Jump", true);
47             }
48             else
49             {
50                 animator.SetBool("Jump", false);
51             }
52
53             if(Input.GetButtonDown("Fire2") && animator.layerCount >= 2)
54             {
55                 animator.SetBool("Hi", !animator.GetBool("Hi"));
56             }
57
58
59             float h = Input.GetAxis("Horizontal");
60             float v = Input.GetAxis("Vertical");
61
62             if( v < 0 )
63             {
64                 v = 0;
65             }
66
67             animator.SetFloat( "Speed", h*h+v*v );
68             animator.SetFloat( "Direction", h, DirectionDampTime, Time.deltaTime );
69
70             float direction = animator.GetFloat( "Direction" );
71
72             float targetSpeedModifier = Mathf.Abs( v );
73
74             if( Mathf.Abs( direction ) > 0.2f )
75             {
76                 targetSpeedModifier = TurnSpeedModifier;
77             }
78
79             m_SpeedModifier = Mathf.MoveTowards( m_SpeedModifier, targetSpeedModifier, Time.deltaTime * 25f );
80
81             Vector3 speed = transform.forward * SynchronizedMaxSpeed * m_SpeedModifier;
82             float turnSpeed = direction * SynchronizedTurnSpeed;
83
84             /*float moveDistance = Vector3.Distance( transform.position, m_LastPosition ) / Time.deltaTime;
85
86             if( moveDistance < 4f && turnSpeed == 0f )
87             {
88                 speed = transform.forward * moveDistance;
89             }*/
90
91             //Debug.Log( moveDistance );
92             //Debug.Log( speed + " - " + speed.magnitude + " - " + speedModifier + " - " + h + " - " + v );
93
94             m_TransformView.SetSynchronizedValues( speed, turnSpeed );
95
96             //m_LastPosition = transform.position;
97          }
98     }
File name: Animals.cs Copy
14         public void Start()
15         {
16             string[] names = new string[] { "dog", "monkey", "pig", "fox", "giraffe", "panda", "rhino", "tiger", "elephant", "lion" };
17
18             animals = new List();
19             int animalIndex = 0;
20
21             UpgradeInfo upgradeInfo = new UpgradeInfo();
22
23             GameObject animalPlayer = (GameObject)Instantiate(Resources.Load("Animals/" + names[Attr.currentAnimal]));
24             animalPlayer.transform.parent = gameObject.transform;
25             animalPlayer.transform.localPosition = new Vector3(-3.5f + 0.7f * animalIndex, -0.9f, 0);
26             setSortingLayer(animalPlayer, "Animal8");
27             Animal player = animalPlayer.AddComponent();
28             player.setAnimalName(names[Attr.currentAnimal]);
29             player.animalIndex = animalIndex;
30             player.gameScreen = gameScreen;
31             float speedPlayer = upgradeInfo.getItem(Attr.currentAnimal, 0, false);
32             float jumpPlayer = upgradeInfo.getItem(Attr.currentAnimal, 1, false);
33             player.setAnimalProperties(speedPlayer, jumpPlayer);
34             animalPlayer.layer = LayerMask.NameToLayer("Animal1");
35
36             animals.Add(animalPlayer);
37             animalIndex++;
38
39             animalPlayer.GetComponent().Play("run");
40             //animalPlayer.GetComponent().SetBool(Animal.IS_PLAYER, true);
41
42             TextAsset xml = Resources.Load("Levels/WorldMap" + (Attr.currentWorld + 1));
43             XmlDocument xmlDoc = new XmlDocument();
44             xmlDoc.Load(new StringReader(xml.text));
45
46             XmlNodeList xmlNodeList = xmlDoc.DocumentElement.ChildNodes;
47             XmlNodeList levelNodeList = xmlNodeList.Item(Attr.currentLevel).ChildNodes;
48             for (int i = 0; i < levelNodeList.Count; i++)
49             {
50                 int numberAnimal = int.Parse(levelNodeList.Item(i).Attributes.Item(0).Value);
51                 string animalName = levelNodeList.Item(i).Attributes.Item(1).Value.ToLower();
52
53                 for (int k = 0; k < numberAnimal; k++)
54                 {
55                     GameObject animalObject = (GameObject)Instantiate(Resources.Load("Animals/" + animalName));
56                     animalObject.transform.parent = gameObject.transform;
57                     animalObject.transform.localPosition = new Vector3(-3.5f + 0.7f*animalIndex, -0.9f, 0);
58                     setSortingLayer(animalObject, "Animal" + animalIndex);
59                     Animal animal = animalObject.AddComponent();
60                     animal.setAnimalName(animalName.ToLower() + "_blue");
61                     animal.animalIndex = animalIndex;
62                     animal.gameScreen = gameScreen;
63                     float speed = upgradeInfo.getSpeed(i);
64                     float jump = upgradeInfo.getJump(i);
65                     animal.setAnimalProperties(speed, jump);
66                     animalObject.layer = LayerMask.NameToLayer("Animal" + (animalIndex + 1));
67                     animals.Add(animalObject);
68                     animalIndex++;
69
70                     animalObject.GetComponent().Play("run_blue");
71
72                     //animalObject.GetComponent().SetBool(Animal.IS_PLAYER, false);
73                 }
74             }
75         }
File name: ShopScreen.cs Copy
128     public void updateUI()
129     {
130         upgradeLayer.resetChooseItem();
131         buyLayer.setParams(upgradeInfo.getSpeed(Attr.currentAnimal), upgradeInfo.getJump(Attr.currentAnimal),
132             starCosts[Attr.currentAnimal], goldCosts[Attr.currentAnimal]);
133
134
135
136     }
File name: UpgradeInfo.cs Copy
59     public int getSpeed(int animalIndex)
60     {
61         return speeds[animalIndex];
62     }

GetSpeed 136 lượt xem

Gõ tìm kiếm nhanh...