在CSS中改变CSS类属性

时间:2017-02-06 12:53:04

标签: css css3

在CSS中,我想知道是否有某种方式可以通过一个类来使用给予元素的属性,这个类会覆盖从类中给出的类。例如,它看起来像这样:

using UnityEngine;
using System.Collections;

    public class SwipeChecker : MonoBehaviour

    {

    public float maxTime;
    public float minSwipeDistance;

    float startTime;
    float endTime;

    Vector3 startPos;
    Vector3 endPos;

    float swipeDistance;
    float swipeTime;
    public float swipeScore;

    public GameObject left;
    public GameObject right;
    public GameObject up;
    public GameObject down;
    public GameObject swipeChecker;
    public GameObject[] platforms = new GameObject[5];

    public bool leftSwipe;
    public bool rightSwipe;
    public bool upSwipe;
    public bool downSwipe;


    public int strike;
    public int totalStrikes;



    public GameObject closestPlatform;


    // Use this for initialization

    public GameObject FindClosestPlatform()
    {

        GameObject[] gos;

        gos = GameObject.FindGameObjectsWithTag("platform");


        GameObject closest = null;
        float distance = Mathf.Infinity;
        Vector3 position = transform.position;
        foreach (GameObject go in gos)

        {
            Vector3 diff = go.transform.position - position;
            float curDistance = diff.sqrMagnitude;
            if (curDistance < distance)
            {
                closest = go;
                distance = curDistance;
            }
        }
        return closest;
    }

    public IEnumerator leftwait()
    {
        leftSwipe = true;
        yield return new WaitForSeconds(2);
        leftSwipe = false;
    }

    public IEnumerator rightwait()
    {
        rightSwipe = true;
        yield return new WaitForSeconds(2);
       rightSwipe = false;
    }
    public IEnumerator upwait()
    {
        upSwipe = true;
        yield return new WaitForSeconds(2);
        upSwipe = false;
    }
    public IEnumerator downwait()
    {
        downSwipe = true;
        yield return new WaitForSeconds(2);
        downSwipe = false;
    }
    public IEnumerator pause()
    {

        yield return new WaitForSeconds(2.0f);

    }


    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        if (strike == 1)
        {
            totalStrikes= totalStrikes + 1 ;

        }
        strike = 0;

        closestPlatform = FindClosestPlatform();
        left = GameObject.Find("PurpleTile(Clone)");
       right = GameObject.Find("OrangeTile(Clone)");
        up = GameObject.Find("BlueTile(Clone)");
        down = GameObject.Find("RedTile(Clone)");


        if ((closestPlatform == left) && !leftSwipe) { strike += 1;

        }
        if ((closestPlatform == right) && !rightSwipe)
        {
            strike += 1;

        }
        if ((closestPlatform == up) && !upSwipe)
        {
            strike += 1;


        }
        if ((closestPlatform == down) && !downSwipe)
        {
            strike += 1;


        }   


        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);

            if (touch.phase == TouchPhase.Began)
            {
                startTime = Time.time;
                startPos = touch.position;
            }
            else if (touch.phase == TouchPhase.Ended)
            {
                endTime = Time.time;
                endPos = touch.position;

                swipeDistance = (endPos - startPos).magnitude;
                swipeTime = endTime - startTime;

                if (swipeTime < maxTime && swipeDistance > minSwipeDistance)
                {
                    swipe();
                }
            }

        }

    }


    void swipe()
    {    

        Vector2 distance = endPos - startPos;
            if (Mathf.Abs(distance.x) > Mathf.Abs(distance.y))
            {
                Debug.Log("Horizontal Swipe");
                if (distance.x > 0)
                {
                    Debug.Log("Right Swipe");
                rightSwipe = true;
                StartCoroutine(rightwait());
            }
                if (distance.x < 0)
                {
                    Debug.Log("Left Swipe");
                    StartCoroutine(leftwait());

                }

            }

            else if (Mathf.Abs(distance.x) < Mathf.Abs(distance.y))
            {
                Debug.Log("Vertical Swipe");
                if (distance.y > 0)
                {
                    Debug.Log("Up Swipe");
                    StartCoroutine(upwait());
                }
                if (distance.y < 0)
                {
                    Debug.Log("Down Swipe");
                    StartCoroutine(downwait());
                }
            }


        }

    }

HTML看起来像这样:

.div_class {
  font-family: Arial;
  color: white;
}

.special_class {
  font-family: "Times New Roman";
  color: green;
}

如果我在代码中出错,请道歉,但这是基本要点。 谢谢!

1 个答案:

答案 0 :(得分:3)

你的代码中有一些错误,如未关闭的标记setState和未公开的css规则,我的意思是你没有在规则中放置一个结束括号。这是一个固定的代码

h3
.div_class {
  font-family: Arial;
  color: yellow;
  text-shadow: 1px 1px 0px #000;
}
.special_class {
  font-family: "Times New Roman";
  color: green;
  text-shadow: initial;
}