-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSphereController.cs
More file actions
105 lines (68 loc) · 2.11 KB
/
SphereController.cs
File metadata and controls
105 lines (68 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
using UnityEngine.UI;
using TMPro;
public class SphereController : MonoBehaviour
{
public void Getvalue(string s){
Debug.Log(s);
PlayerPrefs.SetInt("forcevalue",int.Parse(s));
}
public Rigidbody rb;
public Text velocitydisp;
public int MoveSpeed = 10;
private float speed;
private GameObject spwn;
private float mass=2;
//Increasing the mass of the ball
public void increasemass(){
mass= PlayerPrefs.GetFloat("mass");
if (mass<10){
mass+=2;
PlayerPrefs.SetFloat("mass",mass);}
}
//decreasing the mass of the ball
public void decreasemass(){
mass= PlayerPrefs.GetFloat("mass");
if (mass>3){
mass-=2;
PlayerPrefs.SetFloat("mass",mass);
}
}
//setting initial values
void Start(){
PlayerPrefs.SetFloat("mass",2);
MoveSpeed=0;
velocitydisp.text ="NOT INITIALIZED";
}
//Getting components
void Awake()
{
rb = GetComponent<Rigidbody>();
}
//Updating the values
void Update()
{
MoveSpeed=PlayerPrefs.GetInt("forcevalue");
mass= PlayerPrefs.GetFloat("mass");
if (CrossPlatformInputManager.GetButtonDown("Push")) {
if(MoveSpeed!=0){
rb.AddForce(new Vector3(0f, 0f, MoveSpeed-(0.78f*mass)));
}
}
// velocitydisp.GetComponent<Text>().text ="Velocity= "+ PlayerPrefs.GetFloat("velocity");
}
//Setting the initial push of the object
public void setvelocity(Rigidbody ball){
if(ball!=null)
if(ball.velocity.magnitude!=0){
mass= PlayerPrefs.GetFloat("mass");
MoveSpeed=PlayerPrefs.GetInt("forcevalue");
velocitydisp.text ="Accelaration: " + (MoveSpeed/mass);
}
else
velocitydisp.GetComponent<Text>().text ="################";
}
}