接上一篇:小球酷跑流程。项目代码

unity小球酷跑 流程链接:

unity小球酷跑(删减版)_雨木目qq的博客-CSDN博客

https://blog.csdn.net/qq_53603060/article/details/124152196

代码:

cameramove

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class cameramove : MonoBehaviour {
    public GameObject player;
    private float offset_c;
    // Use this for initialization
    void Start () {
        offset_c = gameObject.transform.position.x - player.transform.position.x;
    }
    
    // Update is called once per frame
    void Update () {
        followcameramove ();
        
    }
    void followcameramove(){
        gameObject.transform.position = new Vector3 (offset_c + player.transform.position.x, gameObject.transform.position.y, gameObject.transform.position.z);
    }
}

playermove

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class playermove : MonoBehaviour {
    public Rigidbody rd;
    public float speedautomove=10;
    public float speedup = 20;
    public GameObject player;
    //public int score = 0;
    public GameObject down;
    public GameObject pass1;
    void Start () {
        rd=gameObject.GetComponent<Rigidbody> ();
        
    }
    
    // Update is called once per frame
    void Update () {
        
        //playerautomove ();
        playermoveup ();
    }
    private void playerautomove(){
        rd.AddForce (Vector3.right *speedautomove);
    }
    private void playermoveup(){
        float v=Input.GetAxis ("Vertical");
        float h=Input.GetAxis("Horizontal");
        rd.AddForce (h*Vector3.right*speedup);
        //rd.AddForce (h*Vector3.left*speedup);
        rd.AddForce (v*Vector3.up*speedup);
        //rd.AddForce (v*Vector3.down*speedup);
        if (player.transform.position.y > 10 | player.transform.position.y < -10) {
            down.SetActive (true);
            Time.timeScale = 0;
        } 
        else if (player.transform.position.x > 1000) {
            pass1.SetActive (true);
        }
    }
    void  OnCollisionEnter(Collision col)
    {
        
        var tags = col.collider.transform.tag;
        if (col.collider.tag == "barrier") {
            //print (2);
            UIcontrol._instance.rememberscore (-3);
        }
        else if (col.collider.tag == "coin") {
            //print(3);
            UIcontrol._instance.rememberscore (5);
            //score_text.text = score.ToString();
            //Destroy (col.collider.gameObject);
            col.collider.transform.localScale = new Vector3 (0.1f, 0.1f, 0.1f);
        } 
        //else if (col.collider.tag = "wall")
        //{
            //UIcontrol._instance.rememberscore (0);
        //}


    }


}

playercolorCollision

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class playercolorcolloision : MonoBehaviour {

    // Use this for initialization
    void Start () {
        
    }
    
    // Update is called once per frame
    void Update () {
        
    }
    private void OnCollisionEnter(Collision collision){
        gameObject.GetComponent<Renderer> ().material.color =Color.cyan;

    }
    private void OnCollisionExit(Collision collision){
        gameObject.GetComponent<Renderer> ().material.color =Color.red;
    }

}

wallcontrol

using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class wallcontrol : MonoBehaviour {

    private float offset;
    public GameObject player;
    public int score = 10;
    void Start () {
        offset = gameObject.transform.position.x - player.transform.position.x;
        
    }
    
    // Update is called once per frame
    void Update () {
        Followplayermove();

    }

    void Followplayermove(){
        gameObject.transform.position = new Vector3 (player.transform.position.x + offset, 00);
    }

}

barriercontrol

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading;//  import命名空间。 

public class barriercontrol : MonoBehaviour {
    //属性
    public float interval=10;
    public GameObject currentbarrier;
    public GameObject barrier_copy;
    //引用
    public GameObject player;
    public GameObject[] barrier_copys;
    // Use this for initialization
    void Start () {
        
    }
    
    // Update is called once per frame
    void Update () {
        
        Autocreatebarrier();//auto barrier create;
        //Randombarrierposition();
    }
    //障碍自动生成
    public void Autocreatebarrier()
    {
        int j=Random.Range(0,barrier_copys.Length-1);
        print (j);
        barrier_copy=barrier_copys [j];
        
        if(player.transform.position.x>currentbarrier.transform.position.x)
        {
            
            //create new barrier
            GameObject present=currentbarrier;
         
            //Vector3 target=currentbarrier.transform.position+new Vector3(interval,0,0) 要copy的位置
            GameObject g=Instantiate(barrier_copy,currentbarrier.transform.position+new Vector3(interval,0,0),Quaternion.identity);
            //判断障碍change

            currentbarrier=g;
            //print (currentbarrier.transform.color);
            Randombarrierposition();
            Destroy (present);


        }
    }
    //障碍大小和位置
    public void Randombarrierposition()
    {
        var positions= currentbarrier.transform.position;
        var size = currentbarrier.transform.localScale;
        float r = Random.Range (-4,3);
        float sx = Random.Range (1,3);
        float sz = Random.Range (1,3);
        float sy = Random.Range (1,3);
        currentbarrier.transform.localScale = new Vector3(sx,sy,sz);
        currentbarrier.transform.position = new Vector3(positions[0], r, positions[2]);
        //Randomsize (5);

    }
    //障碍位置
    public float randomnumber(int m,int n)
    {
        if (m != n) {
            float r = Random.Range (m, n);
            return r;
        } 
        else {
            return 0;
        }
    }
    
}


   
        

barriercorol

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class barriercolor : MonoBehaviour {

    public Material[] barriersmaterials;

    void Start(){
        int i = Random.Range(0,barriersmaterials.Length-1);
        gameObject.GetComponent<Renderer>().material= barriersmaterials[i];

    }
}


   

UIcontrol

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UIcontrol : MonoBehaviour {

    public Text scoretext;
    public int score;
    public GameObject end;
    public GameObject pass;
    //游戏开发设计模式--单例模式
    public static UIcontrol _instance;

    public void Awake()
    {
        _instance = this;
        //print(1);
    }

    public void rememberscore(int x)
    {
        score += x;
        scoretext.text = "得分"+score;
        //print(111);
        if (score > 55) {
            pass.SetActive (true);
            Time.timeScale = 0;//player 停止,静止ball里的runing
        }
        else if (score <-100) 
        {
            end.SetActive (true);
            Time.timeScale = 0;
        }
    }

}

coincontrol

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class coincontrol : MonoBehaviour {

    // Use this for initialization
    public float interval=15;
    public GameObject currentcoin;
    public GameObject coin_copy;
    //引用
    public GameObject player;
    void Start () {

    }

    // Update is called once per frame
    void Update () {
        Autocreatebarrier ();

    }
    //生成
    public void Autocreatebarrier()
    {
        if(player.transform.position.x>currentcoin.transform.position.x)
        {
            GameObject present=currentcoin;
            //create new coin
            Vector3 targetpos=currentcoin.transform.position+new Vector3(interval,0,0);
            GameObject g=Instantiate(coin_copy,targetpos,Quaternion.identity);
            //判断障碍change
            currentcoin=g;
            Randombarrierposition ();
            Destroy (present);


        }
    }
    //位置
    public void Randombarrierposition()
    {
        var positions= currentcoin.transform.position;
        float r = Random.Range (-1,2);
        currentcoin.transform.position = new Vector3(positions[0], r, positions[2]);


    }
}



 
           

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
"天天"是一款非常受欢迎的手机游戏,如果你想用Python编写与这款游戏相关的代码,通常情况下,这并不是直的游戏编程,因为Python不是原生用于移动游戏开发的语言,尤其是对于像天天这样基于Unity或Cocos这样的跨平台游戏引擎构建的游戏。 然而,你可以使用Python做一些与天天辅助相关的工具,比如数据分析、数据抓取(爬虫)来获取游戏信息,或者是编写一些脚本来自动化某些日常任务,比如自动登录、统计玩家的游戏表现等。这需要用到网络请求库(如requests)、JSON解析以及可能的HTML解析库(如BeautifulSoup)。 具体代码示例可能会涉及到模拟HTTP请求、解析API响应或网页内容,但要注意游戏开发者可能会有反爬虫机制,使用时需遵守游戏服务条款和法律法规。 如果你对这个方向感兴趣,我可以为你提供一个基础框架: ```python import requests from bs4 import BeautifulSoup # 定义URLs login_url = "https://ttxq.qq.com/" game_data_url = "https://api.example.com/ttkprun/data" # 编写登录函数 def login(username, password): with requests.post(login_url, data={"username": username, "password": password}) as response: if response.status_code == 200: # 检查登录状态 # 处理登录后的cookies或session pass # 示例:获取游戏数据 def get_game_data(): session = login("your_username", "your_password") response = session.get(game_data_url) soup = BeautifulSoup(response.text, 'html.parser') # 解析数据 data = soup.find_all('div', class_='game-data') # 假设数据在class为game-data的元素中 for item in data: # 处理item数据 print(item.text) # 调用函数 get_game_data() ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值